Apple 自2014年推出 Swift 语言以来一直都没有作为生产语言来使用, 感觉都快跟 iOS 开发脱节了, 本专栏基于 Swift 5.3 版本的官方文档,链接如下, 旨在深入学习这门已经成熟的开发语言,开篇对文档作一个简单的翻译。
https://docs.swift.org/swift-book/index.html
About Swift
Swift is a fantastic way to write software, whether it’s for phones, desktops, servers, or anything else that runs code. It’s a safe, fast, and interactive programming language that combines the best in modern language thinking with wisdom from the wider Apple engineering culture and the diverse contributions from its open-source community. The compiler is optimized for performance and the language is optimized for development, without compromising on either.
Swift is friendly to new programmers. It’s an industrial-quality programming language that’s as expressive and enjoyable as a scripting language. Writing Swift code in a playground lets you experiment with code and see the results immediately, without the overhead of building and running an app.
Swift defines away large classes of common programming errors by adopting modern programming patterns:
Variables are always initialized before use.
Array indices are checked for out-of-bounds errors.
Integers are checked for overflow.
Optionals ensure that nil values are handled explicitly.
Memory is managed automatically.
Error handling allows controlled recovery from unexpected failures.
Swift code is compiled and optimized to get the most out of modern hardware. The syntax and standard library have been designed based on the guiding principle that the obvious way to write your code should also perform the best. Its combination of safety and speed make Swift an excellent choice for everything from “Hello, world!” to an entire operating system.
Swift combines powerful type inference and pattern matching with a modern, lightweight syntax, allowing complex ideas to be expressed in a clear and concise manner. As a result, code is not just easier to write, but easier to read and maintain as well.
Swift has been years in the making, and it continues to evolve with new features and capabilities. Our goals for Swift are ambitious. We can’t wait to see what you create with it.
简单说下重点:
可手机, 电脑, 服务器以及其他可以运行代码的设备
安全,快速
工业级
自动内存管理
强大的类型推断能力
Version Compatibility
This book describes Swift 5.3, the default version of Swift that’s included in Xcode 12. You can use Xcode 12 to build targets that are written in either Swift 5.3, Swift 4.2, or Swift 4.
When you use Xcode 12 to build Swift 4 and Swift 4.2 code, most Swift 5.3 functionality is available. That said, the following changes are available only to code that uses Swift 5.3 or later:
Functions that return an opaque type require the Swift 5.1 runtime.
The try? expression doesn’t introduce an extra level of optionality to expressions that already return optionals.
Large integer literal initialization expressions are inferred to be of the correct integer type. For example, UInt64(0xffff_ffff_ffff_ffff) evaluates to the correct value rather than overflowing.
A target written in Swift 5.3 can depend on a target that’s written in Swift 4.2 or Swift 4, and vice versa. This means, if you have a large project that’s divided into multiple frameworks, you can migrate your code from Swift 4 to Swift 5.3 one framework at a time.
Xcode 12 才能支持 Swift 5.3
Xcode 也向下支持 Swift 4.2, Swift 4
细节问题后面按知识点一个一个来解释吧。
A Swift Tour
此段略, 我将在下一篇开始直接写 Swift 编程指南.