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.
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
- Updated for Swift 6.2.1.
- Added the Integer Generic Parameters section with information about generic parameters that have a numeric value.
- Added information to the Integers and Floating-Point Numbers sections about choosing between integers and floating-point numbers.
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 casesyntax. - 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.
2025-03-31
- Updated for Swift 6.1.
- Added the Opaque Parameter Types section
with information about using
someas a lightweight syntax for generics. - Added information about the
noasyncargument to the available section.
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
- Updated for Swift 5.10.
- Added information about nested protocols to the Delegation section.
- Added deprecation information in the UIApplicationMain and NSApplicationMain sections.
- 更新至 Swift 5.10。
- 在 代理 章节中 添加了关于嵌套协议的信息。
- 在 UIApplicationMain 和 NSApplicationMain 章节中 添加了弃用信息。
2023-12-11
- Updated for Swift 5.9.2.
- Added information about the
borrowingandconsumingmodifiers 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.
2023-09-18
- Updated for Swift 5.9.
- Added information about
ifandswitchexpressions to the Control Flow chapter and the Conditional Expression section. - Added the Macros chapter, with information about generating code at compile time.
- Expanded the discussion of optionals in The Basics.
- Added an example of concurrency to A Swift Tour.
- Added information about boxed protocol types to the Opaque and Boxed Protocol Types chapter.
- Added information about the
buildPartialBlock(first:)andbuildPartialBlock(accumulated:next:)methods to the Result Transformations section. - Added visionOS to the lists of platforms in available and Conditional Compilation Block.
- Formatted the formal grammar to use blank lines for grouping.
- 更新至 Swift 5.9。
- 在 控制流 章节
和 条件表达式 章节中
添加了关于
if和switch表达式的信息。 - 添加了 宏 章节, 介绍了在编译时生成代码。
- 扩展了 基础知识 中关于可选值的讨论。
- 在 Swift 导览 中添加了并发示例。
- 在 不透明类型和封装协议类型 章节中 添加了关于封装协议类型的信息。
- 在 结果转换 章节中
添加了关于
buildPartialBlock(first:)和buildPartialBlock(accumulated:next:)方法的信息。 - 在 available 和 条件编译代码块: 的平台列表中 添加了 visionOS。
- 格式化了形式文法,使用空行进行分组。
2023-03-30
- Updated for Swift 5.8.
- Added the Deferred Actions section,
showing
deferoutside of error handling. - Adopted Swift-DocC for publication.
- Minor corrections and additions throughout.
- 更新至 Swift 5.8。
- 添加了 延迟执行的操作(Deferred Actions) 章节,
展示了在错误处理之外使用
defer。 - 采用 Swift-DocC 进行发布。
- 全文进行了小幅修正和补充。
2022-09-12
- Updated for Swift 5.7.
- Added the Sendable Types section,
with information about sending data between actors and tasks,
and added information about the
@Sendableand@uncheckedattributes to the Sendable and unchecked sections. - Added the Regular Expression Literals section with information about creating a regular expression.
- Added information about the short form of
if-letto the Optional Binding section. - Added information about
#unavailableto the Checking API Availability section.
2022-03-14
- Updated for Swift 5.6.
- Updated the Explicit Member Expression section
with information about using
#ifaround chained method calls and other postfix expressions. - Updated the visual styling of figures throughout.
- 更新至 Swift 5.6。
- 更新了 显式成员表达式 章节,
添加了关于在链式方法调用和其他后缀表达式中使用
#if的信息。 - 更新了全文的图表视觉样式。
2021-09-20
- Updated for Swift 5.5.
- Added information about asynchronous functions, tasks, and actors to the Concurrency chapter, and to the Actor Declaration, Asynchronous Functions and Methods, and Await Operator sections.
- Updated the Identifiers section with information about identifiers that start with an underscore.
2021-04-26
- Updated for Swift 5.4.
- Added the Result Builders and resultBuilder sections with information about result builders.
- Added the Implicit Conversion to a Pointer Type section with information about how in-out parameters can be implicitly converted to unsafe pointers in a function call.
- Updated the Variadic Parameters and Function Declaration sections, now that a function can have multiple variadic parameters.
- Updated the Implicit Member Expression section, now that implicit member expressions can be chained together.
2020-09-16
- Updated for Swift 5.3.
- Added information about multiple trailing closures to the Trailing Closures section, and added information about how trailing closures are matched to parameters to the Function Call Expression section.
- Added information about synthesized implementations
of
Comparablefor enumerations to the Adopting a Protocol Using a Synthesized Implementation section. - Added the Contextual Where Clauses section
now that you can write a generic
whereclause in more places. - Added the Unowned Optional References section with information about using unowned references with optional values.
- Added information about the
@mainattribute to the main section. - Added
#filePathto the Literal Expression section, and updated the discussion of#file. - Updated the Escaping Closures section,
now that closures can refer to
selfimplicitly in more scenarios. - Updated the Handling Errors Using Do-Catch
and Do Statement sections,
now that a
catchclause can match against multiple errors. - Added more information about
Anyand moved it into the new Any Type section. - Updated the Property Observers section, now that lazy properties can have observers.
- Updated the Protocol Declaration section, now that members of an enumeration can satisfy protocol requirements.
- Updated the Stored Variable Observers and Property Observers section to describe when the getter is called before the observer.
- Updated the Memory Safety chapter to mention atomic operations.
- 更新至 Swift 5.3。
- 在 尾随闭包 章节中 添加了关于多个尾随闭包的信息, 并在 函数调用表达式 章节中 添加了关于尾随闭包如何匹配参数的信息。
- 在 使用合成实现来遵循协议 章节中
添加了关于枚举的
Comparable合成实现的信息。 - 添加了 包含上下文关系的 where 子句 章节,
现在可以在更多地方编写泛型
where子句。 - 添加了 无主可选引用 章节, 介绍了如何将无主引用与可选值一起使用。
- 在 main 章节中
添加了关于
@main特性的信息。 - 在 字面量表达式 章节中添加了
#filePath, 并更新了#file的讨论。 - 更新了 逃逸闭包 章节,
现在闭包可以在更多场景下隐式引用
self。 - 更新了 使用 Do-Catch 处理错误
和 Do 语句 章节,
现在
catch子句可以匹配多个错误。 - 添加了更多关于
Any的信息, 并将其移至新的 Any 类型 章节。 - 更新了 属性观察器 章节, 现在惰性属性可以有观察者。
- 更新了 协议声明 章节, 现在枚举的成员可以满足协议要求。
- 更新了 存储变量观察者和属性观察者 章节, 描述了何时在观察者之前调用 getter。
- 更新了 内存安全 章节, 提及了原子操作。
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
Selfcan 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
- Updated for Swift 5.1.
- Added information about functions that specify a protocol that their return value conforms to, instead of providing a specific named return type, to the Opaque and Boxed Protocol Types chapter.
- Added information about property wrappers to the Property Wrappers section.
- Added information about enumerations and structures that are frozen for library evolution to the frozen section.
- Added the Functions With an Implicit Return
and Shorthand Getter Declaration sections
with information about functions that omit
return. - Added information about using subscripts on types to the Type Subscripts section.
- Updated the Enumeration Case Pattern section, now that an enumeration case pattern can match an optional value.
- Updated the Memberwise Initializers for Structure Types section, now that memberwise initializers support omitting parameters for properties that have a default value.
- Added information about dynamic members that are looked up by key path at runtime to the dynamicMemberLookup section.
- Added
macCatalystto the list of target environments in Conditional Compilation Block. - Updated the Self Type section,
now that
Selfcan be used to refer to the type introduced by the current class, structure, or enumeration declaration.
- 更新至 Swift 5.1。
- 在 不透明类型和封装协议类型 章节中 添加了关于函数指定其返回值遵循的协议 而非提供具体命名返回类型的信息。
- 在 属性包装器 章节中 添加了关于属性包装器的信息。
- 在 frozen 章节中 添加了关于为库演进而冻结的枚举和结构体的信息。
- 添加了 隐式返回的函数
和 简化 Getter 声明 章节,
介绍了省略
return的函数。 - 在 类型下标 章节中 添加了关于在类型上使用下标的信息。
- 更新了 枚举用例模式 章节, 现在枚举 case 模式可以匹配可选值。
- 更新了 结构体逐一成员构造器 章节, 现在成员初始化器支持 为具有默认值的属性省略参数。
- 在 dynamicMemberLookup 章节中 添加了关于在运行时通过键路径查找的动态成员的信息。
- 在 条件编译代码块: 中
将
macCatalyst添加到目标环境列表。 - 更新了 Self 类型 章节,
现在
Self可以用于引用 当前类、结构体或枚举声明引入的类型。
2019-03-25
- Updated for Swift 5.0.
- Added the Extended String Delimiters section and updated the String Literals section with information about extended string delimiters.
- Added the dynamicCallable section
with information about dynamically calling instances as functions
using the
dynamicCallableattribute. - Added the unknown and Switching Over Future Enumeration Cases sections
with information about handling future enumeration cases
in switch statements using
the
unknownswitch case attribute. - Added information about the identity key path (
\.self) to the Key-Path Expression section. - Added information about using the less than (
<) operator in platform conditions to the Conditional Compilation Block section.
- 更新至 Swift 5.0。
- 添加了 扩展字符串分隔符 章节, 并更新了 字符串字面量 章节, 介绍了扩展字符串分隔符。
- 添加了 dynamicCallable 章节,
介绍了使用
dynamicCallable特性 将实例作为函数动态调用的信息。 - 添加了 unknown 和 对未来枚举的
case进行switch章节, 介绍了在 switch 语句中使用unknownswitch case 特性 处理未来枚举 case 的信息。 - 在 Key-Path 表达式 章节中
添加了关于标识键路径(
\.self)的信息。 - 在 条件编译代码块: 章节中
添加了关于在平台条件中使用小于(
<)运算符的信息。
2018-09-17
- Updated for Swift 4.2.
- Added information about accessing all of an enumeration's cases to the Iterating over Enumeration Cases section.
- Added information about
#errorand#warningto the Compile-Time Diagnostic Statement section. - Added information about inlining
to the Declaration Attributes section
under the
inlinableandusableFromInlineattributes. - Added information about members that are looked up by name at runtime
to the Declaration Attributes section
under the
dynamicMemberLookupattribute. - Added information about the
requires_stored_property_initsandwarn_unqualified_accessattributes to the Declaration Attributes section. - Added information about how to conditionally compile code depending on the Swift compiler version being used to the Conditional Compilation Block section.
- Added information about
#dsohandleto the Literal Expression section.
- 更新至 Swift 4.2。
- 在 枚举成员的遍历 章节中 添加了关于访问枚举所有 case 的信息。
- 在 编译时诊断语句 章节中
添加了关于
#error和#warning的信息。 - 在 声明特性 章节的
inlinable和usableFromInline特性下 添加了关于内联的信息。 - 在 声明特性 章节的
dynamicMemberLookup特性下 添加了关于在运行时按名称查找的成员的信息。 - 在 声明特性 章节中
添加了关于
requires_stored_property_inits和warn_unqualified_access特性的信息。 - 在 条件编译代码块: 章节中 添加了关于根据所使用的 Swift 编译器版本 条件编译代码的信息。
- 在 字面量表达式 章节中
添加了关于
#dsohandle的信息。
2018-03-29
- Updated for Swift 4.1.
- Added information about synthesized implementations of equivalence operators to the Equivalence Operators section.
- Added information about conditional protocol conformance to the Extension Declaration section of the Declarations chapter, and to the Conditionally Conforming to a Protocol section of the Protocols chapter.
- Added information about recursive protocol constraints to the Using a Protocol in Its Associated Type's Constraints section.
- Added information about
the
canImport()andtargetEnvironment()platform conditions to Conditional Compilation Block.
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
- Updated for Swift 4.0.
- Added information about exclusive access to memory to the Memory Safety chapter.
- Added the Associated Types with a Generic Where Clause section,
now that you can use generic
whereclauses to constrain associated types. - Added information about multiline string literals to the String Literals section of the Strings and Characters chapter, and to the String Literals section of the Lexical Structure chapter.
- Updated the discussion of the
objcattribute in Declaration Attributes, now that this attribute is inferred in fewer places. - Added the Generic Subscripts section, now that subscripts can be generic.
- Updated the discussion in the Protocol Composition section of the Protocols chapter, and in the Protocol Composition Type section of the Types chapter, now that protocol composition types can contain a superclass requirement.
- Updated the discussion of protocol extensions
in Extension Declaration
now that
finalisn't allowed in them. - Added information about preconditions and fatal errors to the Assertions and Preconditions section.
- 更新至 Swift 4.0。
- 在 内存安全 章节中 添加了关于内存独占访问的信息。
- 添加了 具有泛型 Where 子句的关联类型 章节,
现在可以使用泛型
where子句 来约束关联类型。 - 在 字符串和字符 章节的 字符串字面量 部分, 以及 词法结构 章节的 字符串字面量 部分 添加了关于多行字符串字面量的信息。
- 更新了 声明特性 中
关于
objc特性的讨论, 现在该特性在更少的地方被推断。 - 添加了 泛型下标 章节, 现在下标可以是泛型的。
- 更新了 协议 章节的 协议组合 部分, 以及 类型 章节的 协议组合类型 部分的讨论, 现在协议组合类型可以包含父类要求。
- 更新了 扩展声明 中
关于协议扩展的讨论,
现在不再允许在其中使用
final。 - 在 断言和先决条件 章节中 添加了关于前置条件和致命错误的信息。
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
availableattribute 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), andunowned(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
Anyis 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
openandfileprivateaccess-level modifiers to the Access Control chapter. - Updated the discussion of
inoutin 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
@noescapeand@autoclosureattributes 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,
Errorinstead ofErrorProtocol, and protocol names such asExpressibleByStringLiteralinstead ofStringLiteralConvertible. - Updated the discussion
in the Generic Where Clauses section
of the Generics chapter
and in the Generic Parameters and Arguments chapter,
now that generic
whereclauses 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, andguardstatements use a comma-separated list of conditions withoutwhereclauses. - 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 & Protocol2syntax. - 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
Nevertype. - 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@NSManagedattributes imply the@objcattribute. - Added information about the
@GKInspectableattribute 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
letin function parameters from the Function Declaration section. - Removed the discussion of the
Booleanprotocol from the Statements chapter, now that the protocol has been removed from the Swift standard library. - Corrected the discussion of the
@NSApplicationMainattribute 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
#selectorsyntax for Objective-C selectors to the Selector Expression section. - Updated the discussion of associated types
to use the
associatedtypekeyword in the Associated Types and Protocol Associated Type Declaration sections. - Updated information about initializers that return
nilbefore 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
@objcattribute 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
forloops, 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
- Updated for Swift 2.1.
- Updated the String Interpolation and String Literals sections now that string interpolations can contain string literals.
- Added the Escaping Closures section
with information about the
@noescapeattribute. - Updated the Declaration Attributes and Conditional Compilation Block sections with information about tvOS.
- Added information about the behavior of in-out parameters to the In-Out Parameters section.
- Added information to the Capture Lists section about how values specified in closure capture lists are captured.
- Updated the Accessing Properties Through Optional Chaining section to clarify how assignment through optional chaining behaves.
- Improved the discussion of autoclosures in the Autoclosures section.
- Added an example that uses the
??operator to the A Swift Tour chapter.
2015-09-16
- Updated for Swift 2.0.
- Added information about error handling to the Error Handling chapter, the Do Statement section, the Throw Statement section, the Defer Statement section, and the Try Operator section.
- Updated the Representing and Throwing Errors section,
now that all types can conform to the
ErrorTypeprotocol. - Added information about the new
try?keyword to the Converting Errors to Optional Values section. - Added information about recursive enumerations to the Recursive Enumerations section of the Enumerations chapter and the Enumerations with Cases of Any Type section of the Declarations chapter.
- Added information about API availability checking to the Checking API Availability section of the Control Flow chapter and the Availability Condition section of the Statements chapter.
- Added information about the new
guardstatement to the Early Exit section of the Control Flow chapter and the Guard Statement section of the Statements chapter. - Added information about protocol extensions to the Protocol Extensions section of the Protocols chapter.
- Added information about access control for unit testing to the Access Levels for Unit Test Targets section of the Access Control chapter.
- Added information about the new optional pattern to the Optional Pattern section of the Patterns chapter.
- Updated the Repeat-While section
with information about the
repeat-whileloop. - Updated the Strings and Characters chapter,
now that
Stringno longer conforms to theCollectionTypeprotocol from the Swift standard library. - Added information about the new Swift standard library
print(_:separator:terminator)function to the Printing Constants and Variables section. - Added information about the behavior
of enumeration cases with
Stringraw values to the Implicitly Assigned Raw Values section of the Enumerations chapter and the Enumerations with Cases of a Raw-Value Type section of the Declarations chapter. - Added information about the
@autoclosureattribute --- including its@autoclosure(escaping)form --- to the Autoclosures section. - Updated the Declaration Attributes section
with information about the
@availableand@warn_unused_resultattributes. - Updated the Type Attributes section
with information about the
@conventionattribute. - Added an example of using multiple optional bindings
with a
whereclause to the Optional Binding section. - Added information to the String Literals section
about how concatenating string literals using the
+operator happens at compile time. - Added information to the Metatype Type section about comparing metatype values and using them to construct instances with initializer expressions.
- Added a note to the Debugging with Assertions section about when user-defined assertions are disabled.
- Updated the discussion of the
@NSManagedattribute in the Declaration Attributes section, now that the attribute can be applied to certain instance methods. - Updated the Variadic Parameters section, now that variadic parameters can be declared in any position in a function's parameter list.
- Added information to the Overriding a Failable Initializer section about how a nonfailable initializer can delegate up to a failable initializer by force-unwrapping the result of the superclass's initializer.
- Added information about using enumeration cases as functions to the Enumerations with Cases of Any Type section.
- Added information about explicitly referencing an initializer to the Initializer Expression section.
- Added information about build configuration and line control statements to the Compiler Control Statements section.
- Added a note to the Metatype Type section about constructing class instances from metatype values.
- Added a note to the Weak References section about weak references being unsuitable for caching.
- Updated a note in the Type Properties section to mention that stored type properties are lazily initialized.
- Updated the Capturing Values section to clarify how variables and constants are captured in closures.
- Updated the Declaration Attributes section
to describe when you can apply the
@objcattribute to classes. - Added a note to the Handling Errors section
about the performance of executing a
throwstatement. Added similar information about thedostatement in the Do Statement section. - Updated the Type Properties section with information about stored and computed type properties for classes, structures, and enumerations.
- Updated the Break Statement section with information about labeled break statements.
- Updated a note in the Property Observers section
to clarify the behavior of
willSetanddidSetobservers. - Added a note to the Access Levels section
with information about the scope of
privateaccess. - Added a note to the Weak References section about the differences in weak references between garbage collected systems and ARC.
- Updated the Special Characters in String Literals section with a more precise definition of Unicode scalars.
- 更新至 Swift 2.0。
- 在 错误处理 章节、 Do 语句 部分、 Throw 语句: 部分、 Defer 语句 部分 和 Try 运算符 部分 添加了关于错误处理的信息。
- 更新了 表示与抛出错误 部分,
现在所有类型都可以遵循
ErrorType协议。 - 添加了关于新的
try?关键字的信息 到 将错误转换成可选值 部分。 - 在 枚举 章节的 递归枚举 部分 以及 声明 章节的 任意类型的枚举成员 部分 添加了关于递归枚举的信息。
- 在 控制流 章节的 检测 API 可用性 部分 以及 语句 章节的 可用性条件 部分 添加了关于 API 可用性检查的信息。
- 在 控制流 章节的
提前退出 部分
以及 语句 章节的
Guard 语句 部分
添加了关于新的
guard语句的信息。 - 在 协议 章节的 协议扩展 部分 添加了关于协议扩展的信息。
- 在 访问控制 章节的 单元测试 Target 的访问级别 部分 添加了关于单元测试访问控制的信息。
- 在 模式 章节的 可选模式 部分 添加了关于新的可选模式的信息。
- 更新了 Repeat-While 循环 部分,
添加了关于
repeat-while循环的信息。 - 更新了 字符串和字符 章节,
因为
String不再遵循 Swift 标准库的CollectionType协议。 - 在 打印常量和变量 部分
添加了关于新的 Swift 标准库
print(_:separator:terminator)函数的信息。 - 在 枚举 章节的
原始值的隐式赋值 部分
以及 声明 章节的
带有原始值类型的枚举 部分
添加了关于具有
String原始值的枚举 case 行为的信息。 - 在 自动闭包 部分
添加了关于
@autoclosure特性的信息, 包括其@autoclosure(escaping)形式。 - 更新了 声明特性 部分,
添加了关于
@available和@warn_unused_result特性的信息。 - 更新了 类型特性 部分,
添加了关于
@convention特性的信息。 - 添加了使用多个可选绑定的示例
以及
where子句 到 可选绑定 部分。 - 在 字符串字面量 部分
添加了关于使用
+运算符连接字符串字面量 在编译时发生的信息。 - 在 元类型 部分 添加了关于比较元类型值以及使用它们 通过初始化器表达式构造实例的信息。
- 在 使用断言进行调试 部分 添加了关于何时禁用用户定义断言的注释。
- 更新了 声明特性 部分中
关于
@NSManaged特性的讨论, 现在该特性可以应用于某些实例方法。 - 更新了 可变参数 部分, 现在可变参数可以在函数参数列表的 任何位置声明。
- 在 重写一个可失败构造器 部分 添加了关于非可失败初始化器如何 通过强制解包父类初始化器的结果 向上委托到可失败初始化器的信息。
- 在 任意类型的枚举成员 部分 添加了关于将枚举 case 用作函数的信息。
- 在 构造器表达式 部分 添加了关于显式引用初始化器的信息。
- 在 编译器控制语句 部分 添加了关于构建配置 和行控制语句的信息。
- 在 元类型 部分 添加了关于从元类型值构造类实例的注释。
- 在 弱引用 部分 添加了关于弱引用不适合用于缓存的注释。
- 更新了 类型属性 部分的注释, 提到存储型类型属性是惰性初始化的。
- 更新了 值捕获 部分, 澄清了变量和常量如何在闭包中被捕获。
- 更新了 声明特性 部分,
描述了何时可以将
@objc特性应用于类。 - 在 处理错误 部分
添加了关于执行
throw语句性能的注释。 在 Do 语句 部分 添加了关于do语句的类似信息。 - 更新了 类型属性 部分, 添加了关于类、结构体和枚举的 存储型和计算型类型属性的信息。
- 更新了 Break 语句 章节, 添加了关于带标签的 break 语句的信息。
- 更新了 属性观察器 部分的注释,
澄清了
willSet和didSet观察者的行为。 - 在 访问级别 部分
添加了关于
private访问范围的注释。 - 在 弱引用 部分 添加了关于垃圾回收系统和 ARC 之间 弱引用差异的注释。
- 更新了 字符串字面量的特殊字符 部分, 提供了 Unicode 标量的更精确定义。
2015-04-08
- Updated for Swift 1.2.
- Swift now has a native
Setcollection type. For more information, see Sets. @autoclosureis now an attribute of the parameter declaration, not its type. There's also a new@noescapeparameter declaration attribute. For more information, see Declaration Attributes.- Type methods and properties now use the
statickeyword as a declaration modifier. For more information see Type Variable Properties. - Swift now includes the
as?andas!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
ifstatement 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
@objcprotocols. - Type casts that can fail at runtime
now use the
as?oras!operator, and type casts that are guaranteed not to fail use theasoperator. 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
- Updated for Swift 1.1.
- Added a full guide to Failable Initializers.
- Added a description of Failable Initializer Requirements for protocols.
- Constants and variables of type
Anycan now contain function instances. Updated the example in Type Casting for Any and AnyObject to show how to check for and cast to a function type within aswitchstatement. - Enumerations with raw values
now have a
rawValueproperty rather than atoRaw()method and a failable initializer with arawValueparameter rather than afromRaw()method. For more information, see Raw Values and Enumerations with Cases of a Raw-Value Type. - Added a new reference section about Failable Initializers, which can trigger initialization failure.
- Custom operators can now contain the
?character. Updated the Operators reference to describe the revised rules. Removed a duplicate description of the valid set of operator characters from Custom Operators.
- 更新至 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
StringandCharactervalues can no longer be combined with the addition operator (+) or addition assignment operator (+=). These operators are now used only withStringvalues. Use theStringtype'sappend(_:)method to append a singleCharactervalue onto the end of a string. - Added information about the
availabilityattribute to the Declaration Attributes section. - Optionals no longer implicitly evaluate to
truewhen they have a value andfalsewhen they do not, to avoid confusion when working with optionalBoolvalues. Instead, make an explicit check againstnilwith 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 isnil. - 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 theappend(_:)method, or append a single-item array with the+=operator. - Added a note that the start value
afor the Range Operatorsa...banda..<bmust not be greater than the end valueb. - 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
descriptionproperty. (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
overridemodifier. - Updated the Required Initializers section
to note that the
requiredmodifier 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
@infixattribute. - The
@prefixand@postfixattributes for Prefix and Postfix Operators have been replaced byprefixandpostfixdeclaration 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
@assignmentattribute when defining the function. - The order in which modifiers are specified when defining
Custom Operators has changed.
You now write
prefix operatorrather thanoperator prefix, for example. - Added information about the
dynamicdeclaration 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
Charactertype 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}, wherenis a hexadecimal number between 0 and 10FFFF, the range of Unicode's codespace. - The
NSStringlengthproperty is now mapped onto Swift's nativeStringtype asutf16Count, notutf16count. - Swift's native
Stringtype no longer has anuppercaseStringorlowercaseStringproperty. 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@requiredattributes are now theoptional,lazy,final, andrequiredDeclaration 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
Dictionarynow has a BooleanisEmptyproperty. - Clarified the full list of characters that can be used when defining Custom Operators.
niland the Booleanstrueandfalseare now Literals.- Swift's
Arraytype 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 thanSomeType[]. - 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 globalsort(_:_:)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(_:_:)函数, 以反映新的数组值语义。 - 更新了关于 结构体逐一成员构造器 的信息, 澄清即使结构体的存储属性没有默认值, 也会提供成员逐一初始化器。
- 更新为使用
..<而不是..作为 半开区间运算符。 - 添加了 泛型扩展 的示例。