Skip to Content
The Swift Programming Language

Document Revision History文档修订历史

Review the recent changes to this book.

查看本书的最新更改。

2026-09-14

  • Updated for Swift 6.4.
  • Add information about protocols that have superclass requirements to the Class-Only Protocols section.
  • Added information about raw identifiers to the Identifiers section.
  • Added information about body macros to the attached section.
  • 更新至 Swift 6.4。
  • 在 类专属的协议 章节中 添加了有关具有父类要求的协议的内容。
  • 在 标识符 章节中 添加了有关原始标识符的内容。
  • 在 attached 章节中 添加了有关Body 宏的内容。

2026-03-23

  • Updated for Swift 6.3.
  • Minor corrections and additions throughout.
  • 更新至 Swift 6.3。
  • 全书进行了少量修正和补充。

2025-12-12

  • Updated for Swift 6.2.3.
  • Added the export section with information about exporting definitions to client modules.
  • 更新至 Swift 6.2.3。
  • 添加了 export 章节, 介绍了如何将定义导出到客户端模块。

2025-11-03

  • 更新至 Swift 6.2.1。
  • 添加了 整数泛型参数 章节, 介绍了具有数值的泛型参数。
  • 在 整数 和 浮点数 章节中 添加了关于在整数和浮点数之间进行选择的信息。

2025-09-15

  • Updated for Swift 6.2.
  • Added the Memory Safety section with information about issues that Swift helps you prevent.
  • Added the Patterns section with information about the if case syntax.
  • Added information about the main actor, isolation, and global actors to the Concurrency chapter.
  • Added the Implicit Conformance to a Protocol section with information about conforming to common protocols, without writing the conformance explicitly, and suppressing implicit conformance.
  • Added the Implicit Constraints section with information about generic constraints that require conformance to common protocols.
  • 更新至 Swift 6.2。
  • 添加了 内存安全 章节, 介绍了 Swift 帮助你防止的问题。
  • 添加了 模式 章节, 介绍了 if case 语法。
  • 在 并发 章节中 添加了关于主 actor、隔离和全局 actor 的信息。
  • 添加了 对协议的隐式遵循 章节, 介绍了如何遵循常见协议, 无需显式编写遵循声明, 以及如何抑制隐式遵循。
  • 添加了 隐式约束 章节, 介绍了需要遵循常见协议的泛型约束。

2025-03-31

  • Updated for Swift 6.1.
  • Added the Opaque Parameter Types section with information about using some as a lightweight syntax for generics.
  • Added information about the noasync argument to the available section.
  • 更新至 Swift 6.1。
  • 添加了 不透明参数类型 章节, 介绍了使用 some 作为泛型的轻量级语法。
  • 在 available 章节中 添加了关于 noasync 参数的信息。

2024-09-23

  • Updated for Swift 6.
  • Added the preconcurrency section with information about migrating to strict concurrency checking.
  • Added the Specifying the Error Type section with information about throwing errors of a specific type.
  • Updated the Macro-Expansion Expression section, now that any macro can be used as a default value for a parameter.
  • Added information about package-level access to the Access Control chapter.
  • 更新至 Swift 6。
  • 添加了 preconcurrency 章节, 介绍了如何迁移到严格并发检查。
  • 添加了 指定错误类型 章节, 介绍了如何抛出特定类型的错误。
  • 更新了 宏扩展表达式 章节, 现在任何宏都可以用作参数的默认值。
  • 在 访问控制 章节中 添加了关于包级访问的信息。

2024-03-05

2023-12-11

  • Updated for Swift 5.9.2.
  • Added information about the borrowing and consuming modifiers to the Parameter Modifiers section.
  • Added information in Declaring Constants and Variables about setting a constant's value after its declaration.
  • Added more information about tasks, task groups, and task cancellation to the Concurrency chapter.
  • Added information in the Macros chapter about implementing macros in an existing Swift package.
  • Updated the attached section, now that extension macros have replaced conformance macros.
  • Added the backDeployed section with information about back deployment.
  • 更新至 Swift 5.9.2。
  • 在 参数修饰符 章节中 添加了关于 borrowing 和 consuming 修饰符的信息。
  • 在 声明常量和变量 中 添加了关于在声明后设置常量值的信息。
  • 在 并发 章节中 添加了更多关于任务、任务组和任务取消的信息。
  • 在 宏 章节中 添加了关于在现有 Swift 包中实现宏的信息。
  • 更新了 attached 章节, 现在扩展宏已经取代了遵循宏。
  • 添加了 backDeployed 章节, 介绍了反向部署。

2023-09-18

2023-03-30

  • Updated for Swift 5.8.
  • Added the Deferred Actions section, showing defer outside of error handling.
  • Adopted Swift-DocC for publication.
  • Minor corrections and additions throughout.

2022-09-12

  • 更新至 Swift 5.7。
  • 添加了 可发送类型 章节, 介绍了在 actor 和任务之间发送数据, 并在 Sendable 和 unchecked 章节中 添加了关于 @Sendable 和 @unchecked 特性的信息。
  • 添加了 正则表达式字面量 章节, 介绍了如何创建正则表达式。
  • 在 可选绑定 章节中 添加了关于 if-let 简写形式的信息。
  • 在 检测 API 可用性 章节中 添加了关于 #unavailable 的信息。

2022-03-14

  • Updated for Swift 5.6.
  • Updated the Explicit Member Expression section with information about using #if around chained method calls and other postfix expressions.
  • Updated the visual styling of figures throughout.
  • 更新至 Swift 5.6。
  • 更新了 显式成员表达式 章节, 添加了关于在链式方法调用和其他后缀表达式中使用 #if 的信息。
  • 更新了全文的图表视觉样式。

2021-09-20

2021-04-26

2020-09-16

2020-03-24

  • Updated for Swift 5.2.
  • Added information about passing a key path instead of a closure to the Key-Path Expression section.
  • Added the Methods with Special Names section with information about syntactic sugar the lets instances of classes, structures, and enumerations be used with function call syntax.
  • Updated the Subscript Options section, now that subscripts support parameters with default values.
  • Updated the Self Type section, now that the Self can be used in more contexts.
  • Updated the Implicitly Unwrapped Optionals section to make it clearer that an implicitly unwrapped optional value can be used as either an optional or non-optional value.
  • 更新至 Swift 5.2。
  • 在 Key-Path 表达式 章节中 添加了关于传递键路径而非闭包的信息。
  • 添加了 特殊名称的方法 章节, 介绍了让类、结构体和枚举的实例 能够使用函数调用语法的语法糖。
  • 更新了 下标选项 章节, 现在下标支持具有默认值的参数。
  • 更新了 Self 类型 章节, 现在 Self 可以在更多上下文中使用。
  • 更新了 隐式解包可选 章节, 更清楚地说明了隐式解包可选值 可以用作可选值或非可选值。

2019-09-10

2019-03-25

2018-09-17

  • 更新至 Swift 4.2。
  • 在 枚举成员的遍历 章节中 添加了关于访问枚举所有 case 的信息。
  • 在 编译时诊断语句 章节中 添加了关于 #error 和 #warning 的信息。
  • 在 声明特性 章节的 inlinable 和 usableFromInline 特性下 添加了关于内联的信息。
  • 在 声明特性 章节的 dynamicMemberLookup 特性下 添加了关于在运行时按名称查找的成员的信息。
  • 在 声明特性 章节中 添加了关于 requires_stored_property_inits 和 warn_unqualified_access 特性的信息。
  • 在 条件编译代码块: 章节中 添加了关于根据所使用的 Swift 编译器版本 条件编译代码的信息。
  • 在 字面量表达式 章节中 添加了关于 #dsohandle 的信息。

2018-03-29

2017-12-04

  • Updated for Swift 4.0.3.
  • Updated the Key-Path Expression section, now that key paths support subscript components.
  • 更新至 Swift 4.0.3。
  • 更新了 Key-Path 表达式 章节, 现在键路径支持下标组件。

2017-09-19

2017-03-27

  • Updated for Swift 3.1.
  • Added the Extensions with a Generic Where Clause section with information about extensions that include requirements.
  • Added examples of iterating over a range to the For-In Loops section.
  • Added an example of failable numeric conversions to the Failable Initializers section.
  • Added information to the Declaration Attributes section about using the available attribute with a Swift language version.
  • Updated the discussion in the Function Type section to note that argument labels aren't allowed when writing a function type.
  • Updated the discussion of Swift language version numbers in the Conditional Compilation Block section, now that an optional patch number is allowed.
  • Updated the discussion in the Function Type section, now that Swift distinguishes between functions that take multiple parameters and functions that take a single parameter of a tuple type.
  • Removed the Dynamic Type Expression section from the Expressions chapter, now that type(of:) is a Swift standard library function.
  • 更新至 Swift 3.1。
  • 添加了 具有泛型 Where 子句的扩展 章节, 介绍了包含要求的扩展。
  • 在 For-In 循环 章节中 添加了遍历范围的示例。
  • 在 可失败构造器 章节中 添加了可失败数值转换的示例。
  • 在 声明特性 章节中 添加了关于在 Swift 语言版本中使用 available 特性的信息。
  • 更新了 函数类型 章节的讨论, 指出在编写函数类型时不允许使用参数标签。
  • 更新了 条件编译代码块: 章节中 关于 Swift 语言版本号的讨论, 现在允许可选的补丁版本号。
  • 更新了 函数类型 章节的讨论, 现在 Swift 区分接受多个参数的函数 和接受单个元组类型参数的函数。
  • 从 表达式 章节中 删除了动态类型表达式部分, 因为 type(of:) 现在是 Swift 标准库函数。

2016-10-27

  • Updated for Swift 3.0.1.
  • Updated the discussion of weak and unowned references in the Automatic Reference Counting chapter.
  • Added information about the unowned, unowned(safe), and unowned(unsafe) declaration modifiers in the Declaration Modifiers section.
  • Added a note to the Type Casting for Any and AnyObject section about using an optional value when a value of type Any is expected.
  • Updated the Expressions chapter to separate the discussion of parenthesized expressions and tuple expressions.
  • 更新至 Swift 3.0.1。
  • 更新了 自动引用计数 章节中 关于弱引用和无主引用的讨论。
  • 在 声明修饰符 章节中 添加了关于 unowned、unowned(safe) 和 unowned(unsafe) 声明修饰符的信息。
  • 在 Any 和 AnyObject 的类型转换 章节中 添加了关于在需要 Any 类型值时使用可选值的注释。
  • 更新了 表达式 章节, 分离了括号表达式和元组表达式的讨论。

2016-09-13

  • Updated for Swift 3.0.
  • Updated the discussion of functions in the Functions chapter and the Function Declaration section to note that all parameters get an argument label by default.
  • Updated the discussion of operators in the Advanced Operators chapter, now that you implement them as type methods instead of as global functions.
  • Added information about the open and fileprivate access-level modifiers to the Access Control chapter.
  • Updated the discussion of inout in the Function Declaration section to note that it appears in front of a parameter's type instead of in front of a parameter's name.
  • Updated the discussion of the @noescape and @autoclosure attributes in the Escaping Closures and Autoclosures sections and the Attributes chapter now that they're type attributes, rather than declaration attributes.
  • Added information about operator precedence groups to the Precedence for Custom Infix Operators section of the Advanced Operators chapter, and to the Precedence Group Declaration section of the Declarations chapter.
  • Updated discussion throughout to use macOS instead of OS X, Error instead of ErrorProtocol, and protocol names such as ExpressibleByStringLiteral instead of StringLiteralConvertible.
  • Updated the discussion in the Generic Where Clauses section of the Generics chapter and in the Generic Parameters and Arguments chapter, now that generic where clauses are written at the end of a declaration.
  • Updated the discussion in the Escaping Closures section, now that closures are nonescaping by default.
  • Updated the discussion in the Optional Binding section of the The Basics chapter and the While Statement section of the Statements chapter, now that if, while, and guard statements use a comma-separated list of conditions without where clauses.
  • Added information about switch cases that have multiple patterns to the Switch section of the Control Flow chapter and the Switch Statement section of the Statements chapter.
  • Updated the discussion of function types in the Function Type section now that function argument labels are no longer part of a function's type.
  • Updated the discussion of protocol composition types in the Protocol Composition section of the Protocols chapter and in the Protocol Composition Type section of the Types chapter to use the new Protocol1 & Protocol2 syntax.
  • Updated the discussion in the Dynamic Type Expression section to use the new type(of:) syntax for dynamic type expressions.
  • Updated the discussion of line control statements to use the #sourceLocation(file:line:) syntax in the Line Control Statement section.
  • Updated the discussion in Functions that Never Return to use the new Never type.
  • Added information about playground literals to the Literal Expression section.
  • Updated the discussion in the In-Out Parameters section to note that only nonescaping closures can capture in-out parameters.
  • Updated the discussion about default parameters in the Default Parameter Values section, now that they can't be reordered in function calls.
  • Updated attribute arguments to use a colon in the Attributes chapter.
  • Added information about throwing an error inside the catch block of a rethrowing function to the Rethrowing Functions and Methods section.
  • Added information about accessing the selector of an Objective-C property's getter or setter to the Selector Expression section.
  • Added information to the Type Alias Declaration section about generic type aliases and using type aliases inside of protocols.
  • Updated the discussion of function types in the Function Type section to note that parentheses around the parameter types are required.
  • Updated the Attributes chapter to note that the @IBAction, @IBOutlet, and @NSManaged attributes imply the @objc attribute.
  • Added information about the @GKInspectable attribute to the Declaration Attributes section.
  • Updated the discussion of optional protocol requirements in the Optional Protocol Requirements section to clarify that they're used only in code that interoperates with Objective-C.
  • Removed the discussion of explicitly using let in function parameters from the Function Declaration section.
  • Removed the discussion of the Boolean protocol from the Statements chapter, now that the protocol has been removed from the Swift standard library.
  • Corrected the discussion of the @NSApplicationMain attribute in the Declaration Attributes section.
  • 更新至 Swift 3.0。
  • 更新了 函数 章节 和 函数声明 部分中关于函数的讨论, 指出所有参数默认都有参数标签。
  • 更新了 高级运算符 章节中 关于运算符的讨论, 现在将它们作为类型方法而非全局函数来实现。
  • 在 访问控制 章节中 添加了关于 open 和 fileprivate 访问级别修饰符的信息。
  • 更新了 函数声明 部分中 关于 inout 的讨论, 指出它出现在参数类型之前 而非参数名称之前。
  • 更新了 逃逸闭包 和 自动闭包 部分 以及 特性 章节中 关于 @noescape 和 @autoclosure 特性的讨论, 现在它们是类型特性而非声明特性。
  • 在 高级运算符 章节的 自定义中缀运算符的优先级 部分, 以及 声明 章节的 优先级组声明 部分 添加了关于运算符优先级组的信息。
  • 更新了整个文档的讨论, 使用 macOS 代替 OS X, 使用 Error 代替 ErrorProtocol, 使用 ExpressibleByStringLiteral 等协议名称 代替 StringLiteralConvertible。
  • 更新了 泛型 章节的 泛型 Where 语句 部分 以及 泛型形参和实参 章节的讨论, 现在泛型 where 子句写在声明的末尾。
  • 更新了 逃逸闭包 部分的讨论, 现在闭包默认是非逃逸的。
  • 更新了 基础知识 章节的 可选绑定 部分 以及 语句 章节的 While 语句 部分的讨论, 现在 if、while 和 guard 语句 使用逗号分隔的条件列表而不使用 where 子句。
  • 在 控制流 章节的 Switch 语句 部分 以及 语句 章节的 Switch 语句 部分 添加了关于具有多个模式的 switch case 的信息。
  • 更新了 函数类型 部分中 关于函数类型的讨论, 现在函数参数标签不再是函数类型的一部分。
  • 更新了 协议 章节的 协议组合 部分 以及 类型 章节的 协议组合类型 部分中 关于协议组合类型的讨论, 使用新的 Protocol1 & Protocol2 语法。
  • 更新了动态类型表达式部分的讨论, 使用新的 type(of:) 语法表示动态类型表达式。
  • 更新了 行控制语句 部分中 关于行控制语句的讨论, 使用 #sourceLocation(file:line:) 语法。
  • 更新了 永不返回的函数 中的讨论, 使用新的 Never 类型。
  • 在 字面量表达式 部分 添加了关于 playground 字面量的信息。
  • 更新了 In-Out 参数 部分的讨论, 指出只有非逃逸闭包可以捕获 in-out 参数。
  • 更新了 默认参数值 部分中 关于默认参数的讨论, 现在它们不能在函数调用中重新排序。
  • 更新了特性参数以使用冒号 在 特性 章节中。
  • 在 再抛出函数和方法 部分 添加了关于在重新抛出函数的 catch 块内抛出错误的信息。
  • 在 选择器表达式 部分 添加了关于访问 Objective-C 属性的 getter 或 setter 选择器的信息。
  • 在 类型别名声明 部分 添加了关于泛型类型别名和在协议内使用类型别名的信息。
  • 更新了 函数类型 部分中 关于函数类型的讨论, 指出参数类型周围的括号是必需的。
  • 更新了 特性 章节, 指出 @IBAction、@IBOutlet 和 @NSManaged 特性 隐含了 @objc 特性。
  • 在 声明特性 部分 添加了关于 @GKInspectable 特性的信息。
  • 更新了 可选协议要求 部分中 关于可选协议要求的讨论, 澄清它们仅用于与 Objective-C 互操作的代码。
  • 从 函数声明 部分 删除了关于在函数参数中显式使用 let 的讨论。
  • 从 语句 章节中 删除了关于 Boolean 协议的讨论, 因为该协议已从 Swift 标准库中移除。
  • 修正了 声明特性 部分中 关于 @NSApplicationMain 特性的讨论。

2016-03-21

  • Updated for Swift 2.2.
  • Added information about how to conditionally compile code depending on the version of Swift being used to the Conditional Compilation Block section.
  • Added information about how to distinguish between methods or initializers whose names differ only by the names of their arguments to the Explicit Member Expression section.
  • Added information about the #selector syntax for Objective-C selectors to the Selector Expression section.
  • Updated the discussion of associated types to use the associatedtype keyword in the Associated Types and Protocol Associated Type Declaration sections.
  • Updated information about initializers that return nil before the instance is fully initialized in the Failable Initializers section.
  • Added information about comparing tuples to the Comparison Operators section.
  • Added information about using keywords as external parameter names to the Keywords and Punctuation section.
  • Updated the discussion of the @objc attribute in the Declaration Attributes section to note that enumerations and enumeration cases can use this attribute.
  • Updated the Operators section with discussion of custom operators that contain a dot.
  • Added a note to the Rethrowing Functions and Methods section that rethrowing functions can't directly throw errors.
  • Added a note to the Property Observers section about property observers being called when you pass a property as an in-out parameter.
  • Added a section about error handling to the A Swift Tour chapter.
  • Updated figures in the Weak References section to show the deallocation process more clearly.
  • Removed discussion of C-style for loops, the ++ prefix and postfix operators, and the -- prefix and postfix operators.
  • Removed discussion of variable function arguments and the special syntax for curried functions.
  • 更新至 Swift 2.2。
  • 在 条件编译代码块: 部分 添加了关于如何根据所使用的 Swift 版本 条件编译代码的信息。
  • 在 显式成员表达式 部分 添加了关于如何区分 仅参数名称不同的方法或初始化器的信息。
  • 在 选择器表达式 部分 添加了关于 Objective-C 选择器的 #selector 语法的信息。
  • 在 关联类型 和 协议关联类型声明 部分 更新了关于关联类型的讨论, 使用 associatedtype 关键字。
  • 在 可失败构造器 部分 更新了关于在实例完全初始化之前 返回 nil 的初始化器的信息。
  • 在 比较运算符 章节中 添加了关于比较元组的信息。
  • 在 关键字和标点符号 部分 添加了关于使用关键字作为外部参数名称的信息。
  • 更新了 声明特性 部分中 关于 @objc 特性的讨论, 指出枚举和枚举 case 可以使用该特性。
  • 更新了 运算符 部分, 讨论了包含点的自定义运算符。
  • 在 再抛出函数和方法 部分 添加了注释, 指出重新抛出函数不能直接抛出错误。
  • 在 属性观察器 部分 添加了关于当属性作为 in-out 参数传递时 属性观察者被调用的注释。
  • 在 Swift 导览 章节中 添加了关于错误处理的部分。
  • 更新了 弱引用 部分的图表, 更清楚地展示了释放过程。
  • 删除了关于 C 风格 for 循环、 ++ 前缀和后缀运算符, 以及 -- 前缀和后缀运算符的讨论。
  • 删除了关于可变函数参数 和柯里化函数特殊语法的讨论。

2015-10-20

2015-09-16

2015-04-08

  • Updated for Swift 1.2.
  • Swift now has a native Set collection type. For more information, see Sets.
  • @autoclosure is now an attribute of the parameter declaration, not its type. There's also a new @noescape parameter declaration attribute. For more information, see Declaration Attributes.
  • Type methods and properties now use the static keyword as a declaration modifier. For more information see Type Variable Properties.
  • Swift now includes the as? and as! failable downcast operators. For more information, see Checking for Protocol Conformance.
  • Added a new guide section about String Indices.
  • Removed the overflow division (&/) and overflow remainder (&%) operators from Overflow Operators.
  • Updated the rules for constant and constant property declaration and initialization. For more information, see Constant Declaration.
  • Updated the definition of Unicode scalars in string literals. See Special Characters in String Literals.
  • Updated Range Operators to note that a half-open range with the same start and end index will be empty.
  • Updated Closures Are Reference Types to clarify the capturing rules for variables.
  • Updated Value Overflow to clarify the overflow behavior of signed and unsigned integers
  • Updated Protocol Declaration to clarify protocol declaration scope and members.
  • Updated Defining a Capture List to clarify the syntax for weak and unowned references in closure capture lists.
  • Updated Operators to explicitly mention examples of supported characters for custom operators, such as those in the Mathematical Operators, Miscellaneous Symbols, and Dingbats Unicode blocks.
  • Constants can now be declared without being initialized in local function scope. They must have a set value before first use. For more information, see Constant Declaration.
  • In an initializer, constant properties can now only assign a value once. For more information, see Assigning Constant Properties During Initialization.
  • Multiple optional bindings can now appear in a single if statement as a comma-separated list of assignment expressions. For more information, see Optional Binding.
  • An Optional-Chaining Expression must appear within a postfix expression.
  • Protocol casts are no longer limited to @objc protocols.
  • Type casts that can fail at runtime now use the as? or as! operator, and type casts that are guaranteed not to fail use the as operator. For more information, see Type-Casting Operators.
  • 更新至 Swift 1.2。
  • Swift 现在有原生的 Set 集合类型。 更多信息请参阅 集合。
  • @autoclosure 现在是参数声明的特性, 而不是其类型的特性。 还有一个新的 @noescape 参数声明特性。 更多信息请参阅 声明特性。
  • 类型方法和属性现在使用 static 关键字 作为声明修饰符。 更多信息请参阅 类型变量属性。
  • Swift 现在包含 as? 和 as! 可失败向下转型运算符。 更多信息请参阅 检查是否遵循协议。
  • 添加了关于 字符串索引 的新指南章节。
  • 从 溢出运算符 中 删除了溢出除法(&/)和 溢出求余(&%)运算符。
  • 更新了常量和 常量属性声明与初始化的规则。 更多信息请参阅 常量声明。
  • 更新了字符串字面量中 Unicode 标量的定义。 参阅 字符串字面量的特殊字符。
  • 更新了 区间运算符,注明 起始和结束索引相同的半开区间将为空。
  • 更新了 闭包是引用类型,澄清 变量的捕获规则。
  • 更新了 值溢出,澄清 有符号和无符号整数的溢出行为。
  • 更新了 协议声明,澄清 协议声明作用域和成员。
  • 更新了 定义捕获列表, 澄清闭包捕获列表中 弱引用和无主引用的语法。
  • 更新了 运算符,明确提及 自定义运算符支持的字符示例, 例如数学运算符、杂项符号 和装饰符号 Unicode 块中的字符。
  • 常量现在可以在局部函数作用域中 声明而不初始化。 它们必须在首次使用前被赋值。 更多信息请参阅 常量声明。
  • 在初始化器中,常量属性现在只能被赋值一次。 更多信息请参阅 构造过程中常量属性的赋值。
  • 多个可选绑定现在可以出现在单个 if 语句中, 以逗号分隔的赋值表达式列表形式。 更多信息请参阅 可选绑定。
  • 可选链表达式 必须出现在后缀表达式中。
  • 协议转换不再仅限于 @objc 协议。
  • 运行时可能失败的类型转换 现在使用 as? 或 as! 运算符, 而保证不会失败的类型转换使用 as 运算符。 更多信息请参阅 类型转换运算符。

2014-10-16

  • 更新至 Swift 1.1。
  • 添加了关于 可失败构造器 的完整指南。
  • 添加了协议的 可失败构造器要求 说明。
  • 类型为 Any 的常量和变量现在可以包含 函数实例。更新了 Any 和 AnyObject 的类型转换 中的示例, 展示如何在 switch 语句中 检查和转换为函数类型。
  • 具有原始值的枚举 现在具有 rawValue 属性而不是 toRaw() 方法, 以及具有 rawValue 参数的可失败初始化器 而不是 fromRaw() 方法。 更多信息请参阅 原始值 和 带有原始值类型的枚举。
  • 添加了关于 可失败的构造器 的新参考部分, 该部分可以触发初始化失败。
  • 自定义运算符现在可以包含 ? 字符。 更新了 运算符 参考以描述 修订后的规则。 从 自定义运算符 中 删除了运算符字符有效集的重复描述。

2014-08-18

  • New document that describes Swift 1.0, Apple’s new programming language for building iOS and OS X apps.
  • Added a new section about Initializer Requirements in protocols.
  • Added a new section about Class-Only Protocols.
  • Assertions and Preconditions can now use string interpolation. Removed a note to the contrary.
  • Updated the Concatenating Strings and Characters section to reflect the fact that String and Character values can no longer be combined with the addition operator (+) or addition assignment operator (+=). These operators are now used only with String values. Use the String type's append(_:) method to append a single Character value onto the end of a string.
  • Added information about the availability attribute to the Declaration Attributes section.
  • Optionals no longer implicitly evaluate to true when they have a value and false when they do not, to avoid confusion when working with optional Bool values. Instead, make an explicit check against nil with the == or != operators to find out if an optional contains a value.
  • Swift now has a Nil-Coalescing Operator (a ?? b), which unwraps an optional's value if it exists, or returns a default value if the optional is nil.
  • Updated and expanded the Comparing Strings section to reflect and demonstrate that string and character comparison and prefix / suffix comparison are now based on Unicode canonical equivalence of extended grapheme clusters.
  • You can now try to set a property's value, assign to a subscript, or call a mutating method or operator through Optional Chaining. The information about Accessing Properties Through Optional Chaining has been updated accordingly, and the examples of checking for method call success in Calling Methods Through Optional Chaining have been expanded to show how to check for property setting success.
  • Added a new section about Accessing Subscripts of Optional Type through optional chaining.
  • Updated the Accessing and Modifying an Array section to note that you can no longer append a single item to an array with the += operator. Instead, use the append(_:) method, or append a single-item array with the += operator.
  • Added a note that the start value a for the Range Operators a...b and a..<b must not be greater than the end value b.
  • Rewrote the Inheritance chapter to remove its introductory coverage of initializer overrides. This chapter now focuses more on the addition of new functionality in a subclass, and the modification of existing functionality with overrides. The chapter's example of Overriding Property Getters and Setters has been rewritten to show how to override a description property. (The examples of modifying an inherited property's default value in a subclass initializer have been moved to the Initialization chapter.)
  • Updated the Initializer Inheritance and Overriding section to note that overrides of a designated initializer must now be marked with the override modifier.
  • Updated the Required Initializers section to note that the required modifier is now written before every subclass implementation of a required initializer, and that the requirements for required initializers can now be satisfied by automatically inherited initializers.
  • Infix Operator Methods no longer require the @infix attribute.
  • The @prefix and @postfix attributes for Prefix and Postfix Operators have been replaced by prefix and postfix declaration modifiers.
  • Added a note about the order in which Prefix and Postfix Operators are applied when both a prefix and a postfix operator are applied to the same operand.
  • Operator functions for Compound Assignment Operators no longer use the @assignment attribute when defining the function.
  • The order in which modifiers are specified when defining Custom Operators has changed. You now write prefix operator rather than operator prefix, for example.
  • Added information about the dynamic declaration modifier in Declaration Modifiers.
  • Added information about how type inference works with Literals.
  • Added more information about curried functions.
  • Added a new chapter about Access Control.
  • Updated the Strings and Characters chapter to reflect the fact that Swift's Character type now represents a single Unicode extended grapheme cluster. Includes a new section on Extended Grapheme Clusters and more information about Unicode Scalar Values and Comparing Strings.
  • Updated the String Literals section to note that Unicode scalars inside string literals are now written as \u{n}, where n is a hexadecimal number between 0 and 10FFFF, the range of Unicode's codespace.
  • The NSString length property is now mapped onto Swift's native String type as utf16Count, not utf16count.
  • Swift's native String type no longer has an uppercaseString or lowercaseString property. The corresponding section in Strings and Characters has been removed, and various code examples have been updated.
  • Added a new section about Initializer Parameters Without Argument Labels.
  • Added a new section about Required Initializers.
  • Added a new section about Optional Tuple Return Types.
  • Updated the Type Annotations section to note that multiple related variables can be defined on a single line with one type annotation.
  • The @optional, @lazy, @final, and @required attributes are now the optional, lazy, final, and required Declaration Modifiers.
  • Updated the entire book to refer to ..< as the Half-Open Range Operator (rather than the “half-closed range operator”).
  • Updated the Accessing and Modifying a Dictionary section to note that Dictionary now has a Boolean isEmpty property.
  • Clarified the full list of characters that can be used when defining Custom Operators.
  • nil and the Booleans true and false are now Literals.
  • Swift's Array type now has full value semantics. Updated the information about Mutability of Collections and Arrays to reflect the new approach. Also clarified the assignment and copy behavior for strings arrays and dictionaries.
  • Array Type Shorthand Syntax is now written as [SomeType] rather than SomeType[].
  • Added a new section about Dictionary Type Shorthand Syntax, which is written as [KeyType: ValueType].
  • Added a new section about Hash Values for Set Types.
  • Examples of Closure Expressions now use the global sorted(_:_:) function rather than the global sort(_:_:) function, to reflect the new array value semantics.
  • Updated the information about Memberwise Initializers for Structure Types to clarify that the memberwise structure initializer is made available even if a structure's stored properties don't have default values.
  • Updated to ..< rather than .. for the Half-Open Range Operator.
  • Added an example of Extending a Generic Type.
  • 介绍 Swift 1.0 的新文档, Swift 是 Apple 用于构建 iOS 和 OS X 应用的全新编程语言。
  • 添加了关于协议中 构造器要求 的新章节。
  • 添加了关于 类专属的协议 的新章节。
  • 断言和先决条件 现在可以使用字符串插值。 删除了相反的注释。
  • 更新了 连接字符串和字符 章节, 以反映 String 和 Character 值 不能再使用加法运算符(+) 或加法赋值运算符(+=)组合。 这些运算符现在仅用于 String 值。 使用 String 类型的 append(_:) 方法 将单个 Character 值追加到字符串末尾。
  • 在 声明特性 章节中 添加了关于 availability 特性的信息。
  • 可选 不再在有值时隐式求值为 true, 在没有值时求值为 false, 以避免在处理可选 Bool 值时产生混淆。 相反,使用 == 或 != 运算符 对 nil 进行显式检查, 以确定可选值是否包含值。
  • Swift 现在有 空合并运算符 (a ?? b),如果存在则解包可选值, 如果可选值为 nil 则返回默认值。
  • 更新并扩展了 比较字符串 章节, 以反映并演示字符串和字符比较 以及前缀/后缀比较现在基于 扩展字形簇的 Unicode 规范等价性。
  • 你现在可以尝试通过 可选链式调用(Optional Chaining) 设置属性值、分配给下标 或调用可变方法或运算符。 关于 通过可选链式调用访问属性 的信息已相应更新, 通过可选链式调用调用方法 中 检查方法调用成功的示例 已扩展以展示如何检查属性设置成功。
  • 添加了关于通过可选链 访问可选类型的下标 的新章节。
  • 更新了 访问和修改数组 章节, 说明不能再使用 += 运算符 将单个项追加到数组中。 应使用 append(_:) 方法, 或使用 += 运算符追加单元素数组。
  • 添加了注释,说明 区间运算符 a...b 和 a..<b 的起始值 a 不能大于结束值 b。
  • 重写了 继承 章节, 删除了关于初始化器重写的介绍性内容。 本章现在更多地关注 在子类中添加新功能, 以及使用重写修改现有功能。 章节中关于 重写属性 Getter 和 Setter 的示例 已被重写以展示如何重写 description 属性。 (在子类初始化器中修改继承属性默认值的示例 已移至 构造过程 章节。)
  • 更新了 构造器的继承和重写 章节, 说明指定初始化器的重写 现在必须标记为 override 修饰符。
  • 更新了 必要构造器 章节, 说明 required 修饰符现在写在 必需初始化器的每个子类实现之前, 并且必需初始化器的要求 现在可以通过自动继承的初始化器来满足。
  • 中缀 运算符方法 不再需要 @infix 特性。
  • 前缀和后缀运算符 的 @prefix 和 @postfix 特性 已被 prefix 和 postfix 声明修饰符取代。
  • 添加了关于当前缀和后缀运算符 都应用于同一操作数时, 前缀和后缀运算符 应用顺序的注释。
  • 复合赋值运算符 的 运算符函数在定义函数时 不再使用 @assignment 特性。
  • 定义 自定义运算符 时 指定修饰符的顺序已更改。 例如,现在写 prefix operator 而不是 operator prefix。
  • 在 声明修饰符 中 添加了关于 dynamic 声明修饰符的信息。
  • 添加了关于类型推断如何与 字面量 配合工作的信息。
  • 添加了更多关于柯里化函数的信息。
  • 添加了关于 访问控制 的新章节。
  • 更新了 字符串和字符 章节, 以反映 Swift 的 Character 类型现在表示 单个 Unicode 扩展字形簇。 包括关于 可扩展的字形群集 的新章节, 以及关于 Unicode 标量 和 比较字符串 的更多信息。
  • 更新了 字符串字面量 章节, 说明字符串字面量中的 Unicode 标量 现在写作 \u{n}, 其中 n 是介于 0 和 10FFFF 之间的十六进制数字, 即 Unicode 代码空间的范围。
  • NSString 的 length 属性现在映射到 Swift 原生 String 类型为 utf16Count,而不是 utf16count。
  • Swift 原生 String 类型不再有 uppercaseString 或 lowercaseString 属性。 字符串和字符 中 相应的章节 已被删除,各种代码示例已被更新。
  • 添加了关于 不带实参标签的构造器形参 的新章节。
  • 添加了关于 必要构造器 的新章节。
  • 添加了关于 可选元组返回类型 的新章节。
  • 更新了 类型注解 章节,说明 多个相关变量可以在单行中定义, 使用一个类型注解。
  • @optional、@lazy、@final 和 @required 特性 现在是 optional、lazy、final 和 required 声明修饰符。
  • 全书将 ..< 统一称为 半开区间运算符 (而不是“半闭区间运算符”)。
  • 更新了 访问和修改字典 章节, 说明 Dictionary 现在有 布尔值 isEmpty 属性。
  • 澄清了定义 自定义运算符 时 可以使用的完整字符列表。
  • nil 和布尔值 true 和 false 现在是 字面量。
  • Swift 的 Array 类型现在具有完整的值语义。 更新了关于 集合的可变性 和 数组 的信息以反映新方法。 还澄清了字符串、数组和字典的赋值和复制行为。
  • 数组类型简写语法 现在写作 [SomeType] 而不是 SomeType[]。
  • 添加了关于 字典类型简写语法 的新章节, 写作 [KeyType: ValueType]。
  • 添加了关于 集合类型的哈希值 的新章节。
  • 闭包表达式 的示例现在使用 全局 sorted(_:_:) 函数 而不是全局 sort(_:_:) 函数, 以反映新的数组值语义。
  • 更新了关于 结构体逐一成员构造器 的信息, 澄清即使结构体的存储属性没有默认值, 也会提供成员逐一初始化器。
  • 更新为使用 ..< 而不是 .. 作为 半开区间运算符。
  • 添加了 泛型扩展 的示例。