Swift 5.0 官方文档中文翻译 -- (版本兼容)Version Compatibility

该文章翻译自apple官方文档:The Swift Programming Language(Swift 5.0)

 

原文:

This book describes Swift 5, the default version of Swift that’s included in Xcode 10.2. You can use Xcode 10.2 to build targets that are written in either Swift 5, Swift 4.2, or Swift 4.

When you use Xcode 10.2 to build Swift 4 and Swift 4.2 code, most Swift 5 functionality is available. That said, the following changes are available only to Swift 5 code:

  • 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 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 one framework at a time.

译文:

这本书描述Swift 5.0, 这默认版本被收录在Xcode 10.2 内。你可以用Xcode 10.2 去构建一个项目,这项目可以用Swift 5,Swift 4.2 或 Swift 4 写程序.

当你用Xcode 10.2 运行Swift 4 和 Swift 4.2 的代码时,大多数Swift 5的功能是可用的,这就是说,下面的改变只有在 Swift 5 上可用.

  • try?表达式不会为已经返回选项的表达式引入额外级别的可选性。
  • 推断大整数文字初始化表达式是正确的整数类型。例如,UInt64(0xffff_ffff_ffff_ffff)计算为正确的值而不是溢出。

一个用Swift 5 的项目是依赖于一个用Swift 4或者 Swift 4.2写的反之亦然。这就意味着,如果你有一个可以被分为多个framework的大型项目,你可以一次性将你的代码从 Swift 3 迁移到 Swift 4 一个框架。 

***************************************************************************************************************************************************

4.1 原文:

This book describes Swift 4.1, the default version of Swift that’s included in Xcode 9.2. You can use Xcode 9.2 to build targets that are written in either Swift 4 or Swift 3.

S

NOTE

When the Swift 4 compiler is working with Swift 3 code, it identifies its language version as 3.2. As a result, you can use conditional compilation blocks like #if swift(>=3.2) to write code that’s compatible with multiple versions of the Swift compiler.

When you use Xcode 9.2 to build Swift 3 code, most of the new Swift 4 functionality is available. That said, the following features are available only to Swift 4 code:

  • Substring operations return an instance of the Substring type, instead of String.

  • The @objc attribute is implicitly added in fewer places.

  • Extensions to a type in the same file can access that type’s private members.

A target written in Swift 4 can depend on a target that’s written in Swift 3, and vice versa. This means, if you have a large project that’s divided into multiple frameworks, you can migrate your code from Swift 3 to Swift 4 one framework at a time.

 

译文:

这本书描述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(子字符串)操作返回一个 Substring(子字符串)类型的实例,而不是String.

这个@objc 属性被私下里添加到更少的地方.

在同一个文件里,类型扩展可以访问该类型的私有成员。

一个用Swift 4 的项目可以依赖于一个用Swift 3写的反之亦然。这就意味着,如果你有一个可以被分为多个framework的大型项目,你可以一次性将你的代码从 Swift 3 迁移到 Swift 4 一个框架。 

 

 

 

 

 

 

 

 

你可能感兴趣的:(Swift 5.0 官方文档中文翻译 -- (版本兼容)Version Compatibility)