Files
the-swift-programming-langu…/source/chapter1/02_version_compatibility.md
mylittleswift ec82cbd6fe Translations for Swift 4.1 (#777)
* Translations for Chapter 3 part 01 for Swift 4.0/4.1

* update chapter 3 part 02 for swift 4.1

* update chapter 3 part 03 for Swift 4.1

* update chapter 1 part 01 for Swift 4.1

* update chapter 1 part 02 for Swift 4.1

* update chapter 1 part 03 for Swift 4.1

* update chapter 2 part 01 for Swift 4.1

* update chapter 2 part 02 for Swift 4.1

* update chapter 2 part 3 for Swift 4.1

* update "summary" and corrected file names

* update chapter 2 part 4 for Swift 4.1

* update chapter 2 part 5 for Swift 4.1

* update chapter 2 part 6 for Swift 4.1

* update chapter 2 parts 06-11 and other parts' errors

* update chapter 2 parts 12-14

* update chapter 2 parts 14-19

* update all chapter 2

* update whole chapter 1

* update some parts of chapter 3
2018-04-12 16:10:36 +08:00

1.1 KiB
Executable File
Raw Blame History

版本兼容性


4.0 翻译:muhlenXi 2017-09-25

4.1 翻译:mylittleswift

本书描述的是 Swift 4.1,是 Xcode 9.2 中包含的默认版本。你可以用 Xcode 9.2 来构建用 Swift 4 或 Swift 3 写的项目。

注意

当 Swift 4 编译器编译 Swift 3 版本的代码时,它识别的语言版本为 3.2 版本。因此,你可以使用像 #if swift(>=3.2) 条件编译块来编写多版本编译器可以并存的代码。

当你用 Xcode 9.2 编译 Swift 3 的代码Swift 4 中大部分功能是可以使用的。也就是说,下面的功能仅仅是 Swift 4 的代码中可以使用:

  • 字符串的子串操作返回的实例是 Substring 类型,不再是 String 类型。
  • 在更少的地方显式的添加 @objc 属性。
  • 同一文件中类型的扩展可以访问这个类型的私有成员。

用 Swift 4 写的项目可以依赖用 Swift 3 写的项目反之亦然。这意味着如果你将一个大的项目分解成多个框架framework你可以每次一个框架地迁移 Swift 3 代码到 Swift 4。