mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
commit
021517cb74
@ -1,72 +0,0 @@
|
||||
translating---geekpi
|
||||
|
||||
Introducing Swift on Fedora
|
||||
======
|
||||
|
||||
![](https://fedoramagazine.org/wp-content/uploads/2018/09/swift-816x345.jpg)
|
||||
|
||||
Swift is a general-purpose programming language built using a modern approach to safety, performance, and software design patterns. It aims to be the best language for a variety of programming projects, ranging from systems programming to desktop applications and scaling up to cloud services. Read more about it and how to try it out in Fedora.
|
||||
|
||||
### Safe, Fast, Expressive
|
||||
|
||||
Like many modern programming languages, Swift was designed to be safer than C-based languages. For example, variables are always initialized before they can be used. Arrays and integers are checked for overflow. Memory is automatically managed.
|
||||
|
||||
Swift puts intent right in the syntax. To declare a variable, use the var keyword. To declare a constant, use let.
|
||||
|
||||
Swift also guarantees that objects can never be nil; in fact, trying to use an object known to be nil will cause a compile-time error. When using a nil value is appropriate, it supports a mechanism called **optionals**. An optional may contain nil, but is safely unwrapped using the **?** operator.
|
||||
|
||||
Some additional features include:
|
||||
|
||||
* Closures unified with function pointers
|
||||
* Tuples and multiple return values
|
||||
* Generics
|
||||
* Fast and concise iteration over a range or collection
|
||||
* Structs that support methods, extensions, and protocols
|
||||
* Functional programming patterns, e.g., map and filter
|
||||
* Powerful error handling built-in
|
||||
* Advanced control flow with do, guard, defer, and repeat keywords
|
||||
|
||||
|
||||
|
||||
### Try Swift out
|
||||
|
||||
Swift is available in Fedora 28 under then package name **swift-lang**. Once installed, run swift and the REPL console starts up.
|
||||
|
||||
```
|
||||
$ swift
|
||||
Welcome to Swift version 4.2 (swift-4.2-RELEASE). Type :help for assistance.
|
||||
1> let greeting="Hello world!"
|
||||
greeting: String = "Hello world!"
|
||||
2> print(greeting)
|
||||
Hello world!
|
||||
3> greeting = "Hello universe!"
|
||||
error: repl.swift:3:10: error: cannot assign to value: 'greeting' is a 'let' constant
|
||||
greeting = "Hello universe!"
|
||||
~~~~~~~~ ^
|
||||
|
||||
|
||||
3>
|
||||
|
||||
```
|
||||
|
||||
Swift has a growing community, and in particular, a [work group][1] dedicated to making it an efficient and effective server-side programming language. Be sure to visit [its home page][2] for more ways to get involved.
|
||||
|
||||
Photo by [Uillian Vargas][3] on [Unsplash][4].
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/introducing-swift-fedora/
|
||||
|
||||
作者:[Link Dupont][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://fedoramagazine.org/author/linkdupont/
|
||||
[1]: https://swift.org/server/
|
||||
[2]: http://swift.org
|
||||
[3]: https://unsplash.com/photos/7oJpVR1inGk?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
||||
[4]: https://unsplash.com/search/photos/fast?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
70
translated/tech/20181003 Introducing Swift on Fedora.md
Normal file
70
translated/tech/20181003 Introducing Swift on Fedora.md
Normal file
@ -0,0 +1,70 @@
|
||||
介绍 Fedora上的 Swift
|
||||
======
|
||||
|
||||
![](https://fedoramagazine.org/wp-content/uploads/2018/09/swift-816x345.jpg)
|
||||
|
||||
Swift 是一种使用现代方法构建安全性、性能和软件设计模式的通用编程语言。它旨在成为各种编程项目的最佳语言,从系统编程到桌面应用程序,以及扩展到云服务。阅读更多关于它的内容以及如何在 Fedora 中尝试它。
|
||||
|
||||
### 安全、快速、富有表现力
|
||||
|
||||
与许多现代编程语言一样,Swift 被设计为比基于 C 的语言更安全。例如,变量总是在可以使用之前初始化。检查数组和整数是否溢出。内存自动管理。
|
||||
|
||||
Swift 将意图放在语法中。要声明变量,请使用 var 关键字。要声明常量,请使用 let。
|
||||
|
||||
Swift 还保证对象永远不会是 nil。实际上,尝试使用已知为 nil 的对象将导致编译时错误。当使用 nil 值时,它支持一种称为 **optional** 的机制。optional 可能包含 nil,但使用 **?** 运算符可以安全地解包。
|
||||
|
||||
一些额外的功能包括:
|
||||
|
||||
* 与函数指针统一的闭包
|
||||
* 元组和多个返回值
|
||||
* 泛型
|
||||
* 对范围或集合进行快速而简洁的迭代
|
||||
* 支持方法、扩展和协议的结构体
|
||||
* 函数式编程模式,例如 map 和 filter
|
||||
* 内置强大的错误处理
|
||||
* 拥有 do、guard、defer 和 repeat 关键字的高级控制流
|
||||
|
||||
|
||||
|
||||
### 尝试 Swift
|
||||
|
||||
Swift 在 Fedora 28 中可用,包名为 **swift-lang**。安装完成后,运行 swift 并启动 REPL 控制台。
|
||||
|
||||
```
|
||||
$ swift
|
||||
Welcome to Swift version 4.2 (swift-4.2-RELEASE). Type :help for assistance.
|
||||
1> let greeting="Hello world!"
|
||||
greeting: String = "Hello world!"
|
||||
2> print(greeting)
|
||||
Hello world!
|
||||
3> greeting = "Hello universe!"
|
||||
error: repl.swift:3:10: error: cannot assign to value: 'greeting' is a 'let' constant
|
||||
greeting = "Hello universe!"
|
||||
~~~~~~~~ ^
|
||||
|
||||
|
||||
3>
|
||||
|
||||
```
|
||||
|
||||
Swift 有一个不断发展的社区,特别底,有一个[工作组][1]致力于使其成为一种高效且有力的服务器端编程语言。请访问[主页][2]了解更多参与方式。
|
||||
|
||||
图片由 [Uillian Vargas][3] 发布在 [Unsplash][4] 上。
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/introducing-swift-fedora/
|
||||
|
||||
作者:[Link Dupont][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://fedoramagazine.org/author/linkdupont/
|
||||
[1]: https://swift.org/server/
|
||||
[2]: http://swift.org
|
||||
[3]: https://unsplash.com/photos/7oJpVR1inGk?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
||||
[4]: https://unsplash.com/search/photos/fast?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
Loading…
Reference in New Issue
Block a user