From 08a76e561f5ad2845129acebba14d8fa23f49241 Mon Sep 17 00:00:00 2001 From: BqLin Date: Sun, 6 May 2018 19:13:01 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E8=A1=8C=E6=9C=AB=E7=A9=BA?= =?UTF-8?q?=E6=A0=BC=20(#782)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/README.md | 2 +- source/chapter1/02_version_compatibility.md | 2 +- source/chapter1/03_a_swift_tour.md | 4 +- source/chapter2/01_The_Basics.md | 6 +- source/chapter2/02_Basic_Operators.md | 2 +- source/chapter2/03_Strings_and_Characters.md | 30 +- source/chapter2/12_Subscripts.md | 2 +- source/chapter2/14_Initialization.md | 14 +- source/chapter2/21_Protocols.md | 4 +- source/chapter2/22_Generics.md | 2 +- .../23_Automatic_Reference_Counting.md | 10 +- source/chapter2/24_Memory_Safety.md | 14 +- source/chapter2/25_Access_Control.md | 12 +- source/chapter2/26_Advanced_Operators.md | 6 +- .../01_About_the_Language_Reference.md | 4 +- source/chapter3/02_Lexical_Structure.md | 42 +- source/chapter3/03_Types.md | 22 +- source/chapter3/04_Expressions.md | 210 ++-- source/chapter3/05_Statements.md | 220 ++-- source/chapter3/06_Declarations.md | 302 ++--- source/chapter3/07_Attributes.md | 26 +- source/chapter3/08_Patterns.md | 60 +- .../09_Generic_Parameters_and_Arguments.md | 34 +- source/chapter3/10_Summary_of_the_Grammar.md | 1020 ++++++++--------- source/chapter4/03_Ballons.md | 2 +- .../04_Interacting_with_C_Pointers.md | 2 +- .../chapter4/05_Value_and_Reference_Types.md | 2 +- .../06_Access_Control_and_Protected.md | 2 +- source/chapter4/07_Optional_Case_Study.md | 2 +- 29 files changed, 1030 insertions(+), 1030 deletions(-) diff --git a/source/README.md b/source/README.md index ef91745c..1a6f0055 100755 --- a/source/README.md +++ b/source/README.md @@ -1,4 +1,4 @@ -> 2016.9.23: 已经更新到 Swift 3.0。 +> 2016.9.23: 已经更新到 Swift 3.0。 # 3.0 更新说明 Swift 3.0 是自 Swift 开源以来第一个大的版本更新。从语言角度不兼容之前的 Swift 2.2 和 Swift 2.3 版本。Swift 3.0 的更新说明,大家可以查看[官方 blog 的说明](https://swift.org/blog/swift-3-0-released/),也可以关注 [SwiftGG](http://swift.gg) 最新的文章。学习官方文档,是掌握语言特性点的最佳途径,感谢翻译的小伙伴们为 Swift 社区所做贡献! diff --git a/source/chapter1/02_version_compatibility.md b/source/chapter1/02_version_compatibility.md index 0c5fb945..15fb38ea 100755 --- a/source/chapter1/02_version_compatibility.md +++ b/source/chapter1/02_version_compatibility.md @@ -1,6 +1,6 @@ # 版本兼容性 ----------------- - + > 4.0 > 翻译:[muhlenXi](https://github.com/muhlenxi) 2017-09-25 diff --git a/source/chapter1/03_a_swift_tour.md b/source/chapter1/03_a_swift_tour.md index 00c21fe3..69ba7f49 100755 --- a/source/chapter1/03_a_swift_tour.md +++ b/source/chapter1/03_a_swift_tour.md @@ -611,10 +611,10 @@ enum ServerResponse { case result(String, String) case failure(String) } - + let success = ServerResponse.result("6:00 am", "8:09 pm") let failure = ServerResponse.failure("Out of cheese.") - + switch success { case let .result(sunrise, sunset): print("Sunrise is at \(sunrise) and sunset is at \(sunset)") diff --git a/source/chapter2/01_The_Basics.md b/source/chapter2/01_The_Basics.md index 7f21f560..a798b1c2 100755 --- a/source/chapter2/01_The_Basics.md +++ b/source/chapter2/01_The_Basics.md @@ -13,7 +13,7 @@ > 校对:[shanks](http://codebuild.me),[overtrue](https://github.com/overtrue) > 2.2 -> 校对:[SketchK](https://github.com/SketchK) +> 校对:[SketchK](https://github.com/SketchK) > 3.0 > 校对:[CMB](https://github.com/chenmingbiao),版本时间2016-09-13 @@ -676,7 +676,7 @@ if let firstNumber = Int("4"), let secondNumber = Int("42"), firstNumber < secon print("\(firstNumber) < \(secondNumber) < 100") } // 输出 "4 < 42 < 100" - + if let firstNumber = Int("4") { if let secondNumber = Int("42") { if firstNumber < secondNumber && secondNumber < 100 { @@ -774,7 +774,7 @@ do { func makeASandwich() throws { // ... } - + do { try makeASandwich() eatASandwich() diff --git a/source/chapter2/02_Basic_Operators.md b/source/chapter2/02_Basic_Operators.md index a0800fcb..6094751b 100755 --- a/source/chapter2/02_Basic_Operators.md +++ b/source/chapter2/02_Basic_Operators.md @@ -390,7 +390,7 @@ for name in names[2...] { } // Brian // Jack - + for name in names[...2] { print(name) } diff --git a/source/chapter2/03_Strings_and_Characters.md b/source/chapter2/03_Strings_and_Characters.md index 896c31ba..d5ecc153 100755 --- a/source/chapter2/03_Strings_and_Characters.md +++ b/source/chapter2/03_Strings_and_Characters.md @@ -10,7 +10,7 @@ > 2.1 > 翻译:[DianQK](https://github.com/DianQK) -> 校对:[shanks](http://codebuild.me), [Realank](https://github.com/Realank), +> 校对:[shanks](http://codebuild.me), [Realank](https://github.com/Realank), > 2.2 > 校对:[SketchK](https://github.com/SketchK) @@ -18,9 +18,9 @@ > 3.0 > 校对:[CMB](https://github.com/chenmingbiao),版本日期:2016-09-13 > 3.0.1, shanks, 2016-11-11 - + > 4.0 -> 翻译:[kemchenj](https://kemchenj.github.io/) 2017-09-21 +> 翻译:[kemchenj](https://kemchenj.github.io/) 2017-09-21 > 4.1 > 翻译+校对:[mylittleswift](https://github.com/mylittleswift) @@ -43,7 +43,7 @@ - [字符串的 Unicode 表示形式](#unicode_representations_of_strings) *字符串*是是一系列字符的集合,例如 `"hello, world"`,`"albatross"`。Swift 的字符串通过 `String` 类型来表示。 -一个 `String` 的内容可以用许多方式读取,包括作为一个 `Character` 值的集合。 +一个 `String` 的内容可以用许多方式读取,包括作为一个 `Character` 值的集合。 Swift 的 `String` 和 `Character` 类型提供了快速和兼容 Unicode 的方式供你的代码使用。创建和操作字符串的语法与 C 语言中字符串操作相似,轻量并且易读。字符串连接操作只需要简单地通过 `+` 符号将两个字符串相连即可。与 Swift 中其他值一样,能否更改字符串的值,取决于其被定义为常量还是变量。你也可以在字符串内插过程中使用字符串插入常量、变量、字面量表达成更长的字符串,这样可以很容易的创建自定义的字符串值,进行展示、存储以及打印。 @@ -78,7 +78,7 @@ let someString = "Some string literal value" let quotation = """ The White Rabbit put on his spectacles. "Where shall I begin, please your Majesty?" he asked. - + "Begin at the beginning," the King said gravely, "and go on till you come to the end; then stop." """ @@ -99,7 +99,7 @@ These are the same. let softWrappedQuotation = """ The White Rabbit put on his spectacles. "Where shall I begin, \ please your Majesty?" he asked. - + "Begin at the beginning," the King said gravely, "and go on \ till you come to the end; then stop." """ @@ -109,10 +109,10 @@ till you come to the end; then stop." ```swift let lineBreaks = """ - + This string starts with a line break. It also ends with a line break. - + """ ``` @@ -283,11 +283,11 @@ print(badStart + end) // 打印两行: // one // twothree - + let goodStart = """ one two - + """ print(goodStart + end) // 打印三行: @@ -464,7 +464,7 @@ for index in greeting.indices { > 注意 > -> 您可以使用 `startIndex` 和 `endIndex` 属性或者 `index(before:)` 、`index(after:)` 和 `index(_:offsetBy:)` 方法在任意一个确认的并遵循 `Collection` 协议的类型里面,如上文所示是使用在 `String` 中,您也可以使用在 `Array`、`Dictionary` 和 `Set` 中。 +> 您可以使用 `startIndex` 和 `endIndex` 属性或者 `index(before:)` 、`index(after:)` 和 `index(_:offsetBy:)` 方法在任意一个确认的并遵循 `Collection` 协议的类型里面,如上文所示是使用在 `String` 中,您也可以使用在 `Array`、`Dictionary` 和 `Set` 中。 ### 插入和删除 @@ -475,7 +475,7 @@ for index in greeting.indices { var welcome = "hello" welcome.insert("!", at: welcome.endIndex) // welcome 变量现在等于 "hello!" - + welcome.insert(contentsOf:" there", at: welcome.index(before: welcome.endIndex)) // welcome 变量现在等于 "hello there!" ``` @@ -485,7 +485,7 @@ welcome.insert(contentsOf:" there", at: welcome.index(before: welcome.endIndex)) ```swift welcome.remove(at: welcome.index(before: welcome.endIndex)) // welcome 现在等于 "hello there" - + let range = welcome.index(welcome.endIndex, offsetBy: -6).. 注意 > -> 您可以使用 `insert(_:at:)`、`insert(contentsOf:at:)`、`remove(at:)` 和 `removeSubrange(_:)` 方法在任意一个确认的并遵循 `RangeReplaceableCollection` 协议的类型里面,如上文所示是使用在 `String` 中,您也可以使用在 `Array`、`Dictionary` 和 `Set` 中。 +> 您可以使用 `insert(_:at:)`、`insert(contentsOf:at:)`、`remove(at:)` 和 `removeSubrange(_:)` 方法在任意一个确认的并遵循 `RangeReplaceableCollection` 协议的类型里面,如上文所示是使用在 `String` 中,您也可以使用在 `Array`、`Dictionary` 和 `Set` 中。 ## 子字符串 @@ -505,7 +505,7 @@ let greeting = "Hello, world!" let index = greeting.index(of: ",") ?? greeting.endIndex let beginning = greeting[.. 2.2 > 校对:[SketchK](https://github.com/SketchK) 2016-05-13 > 3.0.1,shanks,2016-11-13 - + > 4.0 > 校对:[kemchenj](https://kemchenj.github.io/) 2017-09-21 diff --git a/source/chapter2/14_Initialization.md b/source/chapter2/14_Initialization.md index 329a251e..85395f38 100755 --- a/source/chapter2/14_Initialization.md +++ b/source/chapter2/14_Initialization.md @@ -9,7 +9,7 @@ > 翻译+校对:[chenmingbiao](https://github.com/chenmingbiao) > 2.1 -> 翻译:[Channe](https://github.com/Channe),[Realank](https://github.com/Realank) +> 翻译:[Channe](https://github.com/Channe),[Realank](https://github.com/Realank) > 校对:[shanks](http://codebuild.me),2016-1-23 > 2.2 @@ -377,7 +377,7 @@ Swift 为类类型提供了两种构造器来确保实例中所有存储型属 *指定构造器*是类中最主要的构造器。一个指定构造器将初始化类中提供的所有属性,并根据父类链往上调用父类合适的构造器来实现父类的初始化。 -类倾向于拥有少量指定构造器,普遍的是一个类拥有一个指定构造器。指定构造器在初始化的地方通过“管道”将初始化过程持续到父类链。 +类倾向于拥有少量指定构造器,普遍的是一个类拥有一个指定构造器。指定构造器在初始化的地方通过“管道”将初始化过程持续到父类链。 每一个类都必须至少拥有一个指定构造器。在某些情况下,许多类通过继承了父类中的指定构造器而满足了这个条件。具体内容请参考后续章节[构造器的自动继承](#automatic_initializer_inheritance)。 @@ -746,15 +746,15 @@ for item in breakfastList { ```swift let wholeNumber: Double = 12345.0 let pi = 3.14159 - + if let valueMaintained = Int(exactly: wholeNumber) { print("\(wholeNumber) conversion to Int maintains value of \(valueMaintained)") } // 打印 "12345.0 conversion to Int maintains value of 12345" - + let valueChanged = Int(exactly: pi) // valueChanged 是 Int? 类型,不是 Int 类型 - + if valueChanged == nil { print("\(pi) conversion to Int does not maintain value") } @@ -767,7 +767,7 @@ if valueChanged == nil { struct Animal { let species: String init?(species: String) { - if species.isEmpty { + if species.isEmpty { return nil } self.species = species @@ -994,7 +994,7 @@ class UntitledDocument: Document { 在这个例子中,如果在调用父类的可失败构造器 `init?(name:)` 时传入的是空字符串,那么强制解包操作会引发运行时错误。不过,因为这里是通过非空的字符串常量来调用它,所以并不会发生运行时错误。 -### init!可失败构造器 +### init!可失败构造器 通常来说我们通过在 `init` 关键字后添加问号的方式(`init?`)来定义一个可失败构造器,但你也可以通过在 `init` 后面添加惊叹号的方式来定义一个可失败构造器(`init!`),该可失败构造器将会构建一个对应类型的隐式解包可选类型的对象。 diff --git a/source/chapter2/21_Protocols.md b/source/chapter2/21_Protocols.md index 088f5e7e..f2c24dd0 100644 --- a/source/chapter2/21_Protocols.md +++ b/source/chapter2/21_Protocols.md @@ -13,7 +13,7 @@ > 校对:[shanks](http://codebuild.me) > > 2.2 -> 翻译+校对:[SketchK](https://github.com/SketchK) +> 翻译+校对:[SketchK](https://github.com/SketchK) > > 3.0 > 校对:[CMB](https://github.com/chenmingbiao),版本日期:2016-09-13 @@ -699,7 +699,7 @@ class City: Location, Named { func beginConcert(in location: Location & Named) { print("Hello, \(location.name)!") } - + let seattle = City(name: "Seattle", latitude: 47.6, longitude: -122.3) beginConcert(in: seattle) // Prints "Hello, Seattle!" diff --git a/source/chapter2/22_Generics.md b/source/chapter2/22_Generics.md index 20563d22..19e18bbc 100644 --- a/source/chapter2/22_Generics.md +++ b/source/chapter2/22_Generics.md @@ -76,7 +76,7 @@ func swapTwoStrings(_ a: inout String, _ b: inout String) { a = b b = temporaryA } - + func swapTwoDoubles(_ a: inout Double, _ b: inout Double) { let temporaryA = a a = b diff --git a/source/chapter2/23_Automatic_Reference_Counting.md b/source/chapter2/23_Automatic_Reference_Counting.md index 6d0a2d44..43565ec2 100755 --- a/source/chapter2/23_Automatic_Reference_Counting.md +++ b/source/chapter2/23_Automatic_Reference_Counting.md @@ -210,7 +210,7 @@ Swift 提供了两种办法用来解决你在使用类的属性时所遇到的 > 注意 > -> 当 ARC 设置弱引用为 `nil` 时,属性观察不会被触发。 +> 当 ARC 设置弱引用为 `nil` 时,属性观察不会被触发。 下面的例子跟上面 `Person` 和 `Apartment` 的例子一致,但是有一个重要的区别。这一次,`Apartment` 的 `tenant` 属性被声明为弱引用: @@ -271,10 +271,10 @@ unit4A = nil 上面的两段代码展示了变量 `john` 和 `unit4A` 在被赋值为 `nil` 后,`Person` 实例和 `Apartment` 实例的析构函数都打印出“销毁”的信息。这证明了引用循环被打破了。 - > 注意 - > - > 在使用垃圾收集的系统里,弱指针有时用来实现简单的缓冲机制,因为没有强引用的对象只会在内存压力触发垃圾收集时才被销毁。但是在 ARC 中,一旦值的最后一个强引用被移除,就会被立即销毁,这导致弱引用并不适合上面的用途。 - +> 注意 +> +> 在使用垃圾收集的系统里,弱指针有时用来实现简单的缓冲机制,因为没有强引用的对象只会在内存压力触发垃圾收集时才被销毁。但是在 ARC 中,一旦值的最后一个强引用被移除,就会被立即销毁,这导致弱引用并不适合上面的用途。 + ### 无主引用 diff --git a/source/chapter2/24_Memory_Safety.md b/source/chapter2/24_Memory_Safety.md index b9c5c684..3fade4cf 100644 --- a/source/chapter2/24_Memory_Safety.md +++ b/source/chapter2/24_Memory_Safety.md @@ -28,7 +28,7 @@ Swift 也保证同时访问同一块内存时不会冲突,通过约束代码 ```swift // 向 one 所在的内存区域发起一次写操作 var one = 1 - + // 向 one 所在的内存区域发起一次读操作 print("We're number \(one)!") ``` @@ -42,7 +42,7 @@ print("We're number \(one)!") 而当你添加预算项进入表里的时候,它只是一个临时的,错误的状态,因为总数还没有呗更新。在添加预算项的过程中读取总数就会读取到错误的信息。 这个例子也演示了你在修复内存访问冲突时会遇到的问题:有时修复的方式会有很多种,但哪一种是正确的就不总是那么明显了。在这个例子里,根据你是否需要更新后的总数,$5 和 $320 都可能是正确的值。在你修复访问冲突之前,你需要决定它的倾向。 - + > 注意 > > 如果你写过并发和多线程的代码,内存访问冲突也许是同样的问题。然而,这里访问冲突的讨论是在单线程的情境下讨论的,并没有使用并发或者多线程。 @@ -65,7 +65,7 @@ print("We're number \(one)!") func oneMore(than number: Int) -> Int { return number + 1 } - + var myNumber = 1 myNumber = oneMore(than: myNumber) print(myNumber) @@ -85,11 +85,11 @@ print(myNumber) ```swift var stepSize = 1 - + func increment(_ number: inout Int) { number += stepSize } - + increment(&stepSize) // 错误:stepSize 访问冲突 ``` @@ -104,7 +104,7 @@ increment(&stepSize) // 复制一份副本 var copyOfStepSize = stepSize increment(©OfStepSize) - + // 更新原来的值 stepSize = copyOfStepSize // stepSize 现在的值是 2 @@ -159,7 +159,7 @@ extension Player { balance(&teammate.health, &health) } } - + var oscar = Player(name: "Oscar", health: 10, energy: 10) var maria = Player(name: "Maria", health: 5, energy: 10) oscar.shareHealth(with: &maria) // 正常 diff --git a/source/chapter2/25_Access_Control.md b/source/chapter2/25_Access_Control.md index 18d88b33..df5ca664 100644 --- a/source/chapter2/25_Access_Control.md +++ b/source/chapter2/25_Access_Control.md @@ -12,7 +12,7 @@ > 翻译:[Prayer](https://github.com/futantan) > 校对:[shanks](http://codebuild.me),2015-11-01 -> 2.2 +> 2.2 > 翻译+校对:[SketchK](https://github.com/SketchK) 2016-05-17 > 3.0.1 @@ -77,7 +77,7 @@ Open 只能作用于类和类的成员,它和 Public 的区别如下: * Public 或者其它更严访问级别的类成员,只能在其定义的模块内部的子类中重写。 * Open 的类,可以在其定义的模块中被继承,也可以在引用它的模块中被继承。 * Open 的类成员,可以在其定义的模块中子类中重写,也可以在引用它的模块中的子类重写。 - + 把一个类标记为 `open`,明确的表示你已经充分考虑过外部模块使用此类作为父类的影响,并且设计好了你的类的代码了。 @@ -126,7 +126,7 @@ public class SomePublicClass {} internal class SomeInternalClass {} fileprivate class SomeFilePrivateClass {} private class SomePrivateClass {} - + public var somePublicVariable = 0 internal let someInternalConstant = 0 fileprivate func someFilePrivateFunction() {} @@ -158,18 +158,18 @@ public class SomePublicClass { // 显式 public 类 fileprivate func someFilePrivateMethod() {} // 显式 fileprivate 类成员 private func somePrivateMethod() {} // 显式 private 类成员 } - + class SomeInternalClass { // 隐式 internal 类 var someInternalProperty = 0 // 隐式 internal 类成员 fileprivate func someFilePrivateMethod() {} // 显式 fileprivate 类成员 private func somePrivateMethod() {} // 显式 private 类成员 } - + fileprivate class SomeFilePrivateClass { // 显式 fileprivate 类 func someFilePrivateMethod() {} // 隐式 fileprivate 类成员 private func somePrivateMethod() {} // 显式 private 类成员 } - + private class SomePrivateClass { // 显式 private 类 func somePrivateMethod() {} // 隐式 private 类成员 } diff --git a/source/chapter2/26_Advanced_Operators.md b/source/chapter2/26_Advanced_Operators.md index 4007946d..bb021d90 100644 --- a/source/chapter2/26_Advanced_Operators.md +++ b/source/chapter2/26_Advanced_Operators.md @@ -11,7 +11,7 @@ > 2.1 > 校对:[shanks](http://codebuild.me),2015-11-01 > -> 2.2 +> 2.2 > 翻译+校对:[SketchK](https://github.com/SketchK) 2016-05-17 > > 3.0 @@ -329,7 +329,7 @@ signedOverflow = signedOverflow &- 1 struct Vector2D { var x = 0.0, y = 0.0 } - + extension Vector2D { static func + (left: Vector2D, right: Vector2D) -> Vector2D { return Vector2D(x: left.x + right.x, y: left.y + right.y) @@ -449,7 +449,7 @@ Swift 为以下自定义类型提等价运算符供合成实现: struct Vector3D: Equatable { var x = 0.0, y = 0.0, z = 0.0 } - + let twoThreeFour = Vector3D(x: 2.0, y: 3.0, z: 4.0) let anotherTwoThreeFour = Vector3D(x: 2.0, y: 3.0, z: 4.0) if twoThreeFour == anotherTwoThreeFour { diff --git a/source/chapter3/01_About_the_Language_Reference.md b/source/chapter3/01_About_the_Language_Reference.md index 53215bae..78faf33d 100755 --- a/source/chapter3/01_About_the_Language_Reference.md +++ b/source/chapter3/01_About_the_Language_Reference.md @@ -33,13 +33,13 @@ Swift 语言相对较小,这是由于 Swift 代码中在各种地方出现的 举个例子,getter-setter 方法块的语法定义如下: -> getter-setter 方法块语法 +> getter-setter 方法块语法 > > *getter-setter 方法块* → { [*getter 子句*](05_Declarations.html#getter-clause) [*setter 子句*](05_Declarations.html#setter-clause)可选 } | { [*setter 子句*](05_Declarations.html#setter-clause) [*getter 子句*](05_Declarations.html#getter-clause) } 这个定义表明,一个 getter-setter 方法块可以由一个 getter 分句后跟一个可选的 setter 分句构成,然后用大括号括起来,或者由一个 setter 分句后跟一个 getter 分句构成,然后用大括号括起来。上述的语法产式等价于下面的两个语法产式, : -> getter-setter 方法块语法 +> getter-setter 方法块语法 > > getter-setter 方法块 → { [*getter 子句*](05_Declarations.html#getter-clause) [*setter 子句*](05_Declarations.html#setter-clause)可选 } > getter-setter 方法块 → { [*setter 子句*](05_Declarations.html#setter-clause) [*getter 子句*](05_Declarations.html#getter-clause) } diff --git a/source/chapter3/02_Lexical_Structure.md b/source/chapter3/02_Lexical_Structure.md index a579e9d4..82898153 100755 --- a/source/chapter3/02_Lexical_Structure.md +++ b/source/chapter3/02_Lexical_Structure.md @@ -23,7 +23,7 @@ - [标识符](#identifiers) - [关键字和标点符号](#keywords) - [字面量](#literals) - - [整数字面量](#integer_literals) + - [整数字面量](#integer_literals) - [浮点数字面量](#floating_point_literals) - [字符串字面量](#string_literals) - [运算符](#operators) @@ -61,7 +61,7 @@ Swift 的*“词法结构 (lexical structure)”* 描述了能构成该语言中 > *多行注释内容* → [*多行注释内容项*](#multiline-comment-text-item) [*多行注释内容*](#multiline-comment-text)可选 > *多行注释内容项* → [*多行注释*](#multiline-comment). > *多行注释内容项* → [*注释内容项*](#comment-text-item) -> *多行注释内容项* → 任何 Unicode 标量值, 除了 `/*` 或者 `*/` +> *多行注释内容项* → 任何 Unicode 标量值, 除了 `/*` 或者 `*/` 注释可以包含额外的格式和标记,正如 [*Markup Formatting Reference*](https://developer.apple.com/library/prerelease/ios/documentation/Xcode/Reference/xcode_markup_formatting_ref/index.html#//apple_ref/doc/uid/TP40016497) 所述。 @@ -150,9 +150,9 @@ true // 布尔值字面量 > *数值字面量* → **-**可选 [*整数字面量*](#integer-literal) | **-**可选 [*浮点数字面量*](#floating-point-literal) -> +> > *布尔值字面量* → **true** | **false** -> +> > *nil 字面量* → **nil** @@ -177,21 +177,21 @@ true // 布尔值字面量 > *整数字面量* → [*十六进制字面量*](#hexadecimal-literal) -> *二进制字面量* → **0b** [*二进制数字*](#binary-digit) [*二进制字面量字符组*](#binary-literal-characters)可选 +> *二进制字面量* → **0b** [*二进制数字*](#binary-digit) [*二进制字面量字符组*](#binary-literal-characters)可选 > > *二进制数字* → 数值 0 到 1 -> +> > *二进制字面量字符* → [*二进制数字*](#binary-digit) | _ -> +> > *二进制字面量字符组* → [*二进制字面量字符*](#binary-literal-character) [*二进制字面量字符组*](#binary-literal-characters)可选 > *八进制字面量* → **0o** [*八进字数字*](#octal-digit) [*八进制字符组*](#octal-literal-characters)可选 > > *八进字数字* → 数值 0 到 7 -> +> > *八进制字符* → [*八进字数字*](#octal-digit) | _ -> +> > *八进制字符组* → [*八进制字符*](#octal-literal-character) [*八进制字符组*](#octal-literal-characters)可选 @@ -203,7 +203,7 @@ true // 布尔值字面量 > > *十进制字符* → [*十进制数字*](#decimal-digit) | _ > -> *十进制字符组* → [*十进制字符*](#decimal-literal-character) [*十进制字符组*](#decimal-literal-characters)可选 +> *十进制字符组* → [*十进制字符*](#decimal-literal-character) [*十进制字符组*](#decimal-literal-characters)可选 > *十六进制字面量* → **0x** [*十六进制数字*](#hexadecimal-digit) [*十六进制字面量字符组*](#hexadecimal-literal-characters)可选 @@ -233,12 +233,12 @@ true // 布尔值字面量 > 浮点数字面量语法 > - + > *浮点数字面量* → [*十进制字面量*](#decimal-literal) [*十进制分数*](#decimal-fraction)可选 [*十进制指数*](#decimal-exponent)可选 > *浮点数字面量* → [*十六进制字面量*](#hexadecimal-literal) [*十六进制分数*](#hexadecimal-fraction)可选 [*十六进制指数*](#hexadecimal-exponent) -> *十进制分数* → **.** [*十进制字面量*](#decimal-literal) +> *十进制分数* → **.** [*十进制字面量*](#decimal-literal) > > *十进制指数* → [*十进制指数 e*](#floating-point-e) [*正负号*](#sign)可选 [*十进制字面量*](#decimal-literal) @@ -313,20 +313,20 @@ let textB = "Hello world" > 字符串字面量语法 > -> *字符串字面量* → [*静态字符串字面量*](#static-string-literal) | [*插值字符串字面量*](#interpolated-string-literal) +> *字符串字面量* → [*静态字符串字面量*](#static-string-literal) | [*插值字符串字面量*](#interpolated-string-literal) > *静态字符串字面量* → **"**[*引用文本*](#quoted-text)可选**"** -> -> *引用文本* → [*引用文本项*](#quoted-text-item) [*引用文本*](#quoted-text)可选 +> +> *引用文本* → [*引用文本项*](#quoted-text-item) [*引用文本*](#quoted-text)可选 > > *引用文本项* → [*转义字符*](#escaped-character) > *引用文本项* → 除了 **"**、**\\**、U+000A、U+000D 以外的所有 Unicode 字符 > *插值字符串字面量* → **"**[*插值文本*](#interpolated-text)可选**"** -> -> *插值文本* → [*插值文本项*](#interpolated-text-item) [*插值文本*](#interpolated-text)可选 +> +> *插值文本* → [*插值文本项*](#interpolated-text-item) [*插值文本*](#interpolated-text)可选 > > *插值文本项* → **\\****(**[*表达式*](./04_Expressions.html)**)** | [*引用文本项*](#quoted-text-item) @@ -354,7 +354,7 @@ Swift 标准库定义了许多可供使用的运算符,其中大部分在 [基 运算符两侧的空白被用来区分该运算符是否为前缀运算符、后缀运算符或二元运算符。规则总结如下: * 如果运算符两侧都有空白或两侧都无空白,将被看作二元运算符。例如:`a+++b` 和 `a +++ b` 当中的 `+++` 运算符会被看作二元运算符。 -* 如果运算符只有左侧空白,将被看作一元前缀运算符。例如 `a +++b` 中的 `+++` 运算符会被看做是一元前缀运算符。 +* 如果运算符只有左侧空白,将被看作一元前缀运算符。例如 `a +++b` 中的 `+++` 运算符会被看做是一元前缀运算符。 * 如果运算符只有右侧空白,将被看作一元后缀运算符。例如 `a+++ b` 中的 `+++` 运算符会被看作是一元后缀运算符。 * 如果运算符左侧没有空白并紧跟 `.`,将被看作一元后缀运算符。例如 `a+++.b` 中的 `+++` 运算符会被视为一元后缀运算符(即上式被视为 `a+++ .b` 而不是 `a +++ .b`)。 @@ -387,7 +387,7 @@ Swift 标准库定义了许多可供使用的运算符,其中大部分在 [基 > *头部运算符* → U+2794–U+2BFF > *头部运算符* → U+2E00–U+2E7F > *头部运算符* → U+3001–U+3003 -> *头部运算符* → U+3008–U+3030 +> *头部运算符* → U+3008–U+3030 > *运算符字符* → [*头部运算符*](#operator-head) @@ -402,9 +402,9 @@ Swift 标准库定义了许多可供使用的运算符,其中大部分在 [基 > *头部点运算符* → **..** -> +> > *点运算符字符* → **.** | [*运算符字符*](#operator-character) -> +> > *点运算符字符组* → [*点运算符字符*](#dot-operator-character) [*点运算符字符组*](#dot-operator-characters)可选 diff --git a/source/chapter3/03_Types.md b/source/chapter3/03_Types.md index b01ad3eb..74d77277 100644 --- a/source/chapter3/03_Types.md +++ b/source/chapter3/03_Types.md @@ -94,7 +94,7 @@ let origin: Point = (0, 0) var someValue: ExampleModule.MyType ``` -> 类型标识符语法 +> 类型标识符语法 > > *类型标识符* → [*类型名称*](#type-name) [*泛型参数子句*](08_Generic_Parameters_and_Arguments.html#generic_argument_clause)可选 | [*类型名称*](#type-name) [*泛型参数子句*](08_Generic_Parameters_and_Arguments.html#generic_argument_clause)可选 **.** [*类型标识符*](#type-identifier) @@ -153,14 +153,14 @@ someTuple = (left: 5, right: 5) // 错误:命名类型不匹配 func someFunction(left: Int, right: Int) {} func anotherFunction(left: Int, right: Int) {} func functionWithDifferentLabels(top: Int, bottom: Int) {} - + var f = someFunction // 函数 f 的类型为 (Int, Int) -> Void, 而不是 (left: Int, right: Int) -> Void. f = anotherFunction // 正确 f = functionWithDifferentLabels // 正确 - + func functionWithDifferentArgumentTypes(left: Int, right: String) {} func functionWithDifferentNumberOfArguments(left: Int, right: Int, top: Int) {} - + f = functionWithDifferentArgumentTypes // 错误 f = functionWithDifferentNumberOfArguments // 错误 ``` @@ -215,7 +215,7 @@ func takesTwoFunctions(first: (Any) -> Void, second: (Any) -> Void) { > *函数类型参数* → [*特性列表*](06_Attributes.html#attributes)可选 **输入输出参数**可选 [*类型*](#type) | [*参数标签*](#argument-label) [*类型注解*](#type-annotation) -> *参数标签* → [*标识符*](02_Lexical_Structure.html#identifier) +> *参数标签* → [*标识符*](02_Lexical_Structure.html#identifier) ## 数组类型 @@ -273,7 +273,7 @@ let someDictionary: Dictionary = ["Alex": 31, "Paul": 39] > 字典类型语法 > -> *字典类型* → **[** [*类型*](#type) **:** [*类型*](#type) **]** +> *字典类型* → **[** [*类型*](#type) **:** [*类型*](#type) **]** ## 可选类型 @@ -324,7 +324,7 @@ var explicitlyUnwrappedString: Optional ```swift let tupleOfImplicitlyUnwrappedElements: (Int!, Int!) // 错误 let implicitlyUnwrappedTuple: (Int, Int)! // 正确 - + let arrayOfImplicitlyUnwrappedElements: [Int!] // 错误 let implicitlyUnwrappedArray: [Int]! // 正确 ``` @@ -337,7 +337,7 @@ let implicitlyUnwrappedArray: [Int]! // 正确 关于隐式解析可选类型的更多细节,请参阅 [隐式解析可选类型](../chapter2/01_The_Basics.html#implicityly_unwrapped_optionals)。 -> 隐式解析可选类型语法 +> 隐式解析可选类型语法 > > *隐式解析可选类型* → [*类型*](#type) **!** @@ -362,7 +362,7 @@ let implicitlyUnwrappedArray: [Int]! // 正确 > *协议合成延续* → [*协议标识符*](#protocol-identifier) | [*协议合成类型*](#protocol-composition-type) -> *协议标识符* → [*类型标识符*](#type-identifier) +> *协议标识符* → [*类型标识符*](#type-identifier) ## 元类型 @@ -412,7 +412,7 @@ let anotherInstance = metatype.init(string: "some string") > 元类型语法 > -> *元类型* → [*类型*](#type) **.** **Type** | [*类型*](#type) **.** **Protocol** +> *元类型* → [*类型*](#type) **.** **Type** | [*类型*](#type) **.** **Protocol** ## 类型继承子句 @@ -425,7 +425,7 @@ let anotherInstance = metatype.init(string: "some string") 枚举定义中的类型继承子句可以是一系列协议,或是枚举的原始值类型的命名型类型。在枚举定义中使用类型继承子句来指定原始值类型的例子,请参阅 [原始值](../chapter2/08_Enumerations.html#raw_values)。 -> 类型继承子句语法 +> 类型继承子句语法 > > *类型继承子句* → **:** [*类型继承列表*](#type-inheritance-list) diff --git a/source/chapter3/04_Expressions.md b/source/chapter3/04_Expressions.md index 5b18a0e0..cdecf973 100644 --- a/source/chapter3/04_Expressions.md +++ b/source/chapter3/04_Expressions.md @@ -11,10 +11,10 @@ > 2.1 > 翻译:[mmoaay](https://github.com/mmoaay) -> 2.2 +> 2.2 > 校对:[175](https://github.com/Brian175) -> 3.0 +> 3.0 > 翻译+校对:[chenmingjia](https://github.com/chenmingjia) > 4.1 @@ -38,7 +38,7 @@ - [通配符表达式](#wildcard_expression) - [选择器表达式](#selector_expression) - [后缀表达式](#postfix_expressions) - - [函数调用表达式](#function_call_expression) + - [函数调用表达式](#function_call_expression) - [构造器表达式](#initializer_expression) - [显式成员表达式](#explicit_member_expression) - [后缀 self 表达式](#postfix_self_expression) @@ -51,7 +51,7 @@ Swift 中存在四种表达式:前缀表达式,二元表达式,基本表 通过前缀表达式和二元表达式可以对简单表达式使用各种运算符。基本表达式从概念上讲是最简单的一种表达式,它是一种访问值的方式。后缀表达式则允许你建立复杂的表达式,例如函数调用和成员访问。每种表达式都在下面有详细论述。 -> 表达式语法 +> 表达式语法 > > *表达式* → [*try 运算符*](#try-operator)可选 [*前缀表达式*](#prefix-expression) [*二元表达式列表*](#binary-expressions)可选 @@ -60,7 +60,7 @@ Swift 中存在四种表达式:前缀表达式,二元表达式,基本表 ## 前缀表达式 - + 前缀表达式由可选的前缀运算符和表达式组成。前缀运算符只接收一个参数,表达式则紧随其后。 关于这些运算符的更多信息,请参阅 [基本运算符](../chapter2/02_Basic_Operators.md) 和 [高级运算符](../chapter2/25_Advanced_Operators.md)。 @@ -69,7 +69,7 @@ Swift 中存在四种表达式:前缀表达式,二元表达式,基本表 除了标准库运算符,你也可以对某个变量使用 `&` 运算符,从而将其传递给函数的输入输出参数。更多信息,请参阅 [输入输出参数](../chapter2/06_Functions.html#in_out_parameters)。 -> 前缀表达式语法 +> 前缀表达式语法 > > *前缀表达式* → [*前缀运算符*](02_Lexical_Structure.md#prefix-operator)可选 [*后缀表达式*](#postfix-expression) @@ -109,7 +109,7 @@ sum = (try someThrowingFunction()) + anotherThrowingFunction() // 错误:try 关于 `try`、`try?` 和 `try!` 的更多信息,以及该如何使用的例子,请参阅 [错误处理](../chapter2/18_Error_Handling.html)。 > Try 表达式语法 > - + > *try 运算符* → **try** | **try?** | **try!** @@ -128,14 +128,14 @@ sum = (try someThrowingFunction()) + anotherThrowingFunction() // 错误:try > 在解析时,一个二元表达式将作为一个扁平列表表示,然后根据运算符的优先级,再进一步进行组合。例如,`2 + 3 * 5` 首先被看作具有五个元素的列表,即 `2`、`+`、`3`、`*`、`5`,随后根据运算符优先级组合为 `(2 + (3 * 5))`。 -> 二元表达式语法 +> 二元表达式语法 > -> *二元表达式* → [*二元运算符*](02_Lexical_Structure.md#binary-operator) [*前缀表达式*](#prefix-expression). -> *二元表达式* → [*赋值运算符*](#assignment-operator) [*try 运算符*](#try-operator)可选 [*前缀表达式*](#prefix-expression) -> *二元表达式* → [*条件运算符*](#conditional-operator) [*try 运算符*](#try-operator)可选 [*前缀表达式*](#prefix-expression) -> *二元表达式* → [*类型转换运算符*](#type-casting-operator) +> *二元表达式* → [*二元运算符*](02_Lexical_Structure.md#binary-operator) [*前缀表达式*](#prefix-expression) +> *二元表达式* → [*赋值运算符*](#assignment-operator) [*try 运算符*](#try-operator)可选 [*前缀表达式*](#prefix-expression) +> *二元表达式* → [*条件运算符*](#conditional-operator) [*try 运算符*](#try-operator)可选 [*前缀表达式*](#prefix-expression) +> *二元表达式* → [*类型转换运算符*](#type-casting-operator) -> *二元表达式列表* → [*二元表达式*](#binary-expression) [*二元表达式列表*](#binary-expressions)可选 +> *二元表达式列表* → [*二元表达式*](#binary-expression) [*二元表达式列表*](#binary-expressions)可选 ### 赋值表达式 @@ -153,7 +153,7 @@ sum = (try someThrowingFunction()) + anotherThrowingFunction() // 错误:try 赋值运算符不返回任何值。 -> 赋值运算符语法 +> 赋值运算符语法 > > *赋值运算符* → **=** @@ -169,7 +169,7 @@ sum = (try someThrowingFunction()) + anotherThrowingFunction() // 错误:try 关于使用三元条件运算符的例子,请参阅 [三元条件运算符](../chapter2/02_Basic_Operators.md#ternary_conditional_operator)。 -> 三元条件运算符语法 +> 三元条件运算符语法 > > *三元条件运算符* → **?** [*表达式*](#expression) **:** @@ -197,11 +197,11 @@ func f(int: Int) { print("Function for Int") } let x = 10 f(x) // 打印 “Function for Int” - + let y: Any = x f(y) // 打印 “Function for Any” - + f(x as Any) // 打印 “Function for Any” ``` @@ -215,12 +215,12 @@ f(x as Any) 关于类型转换的更多内容和例子,请参阅 [类型转换](../chapter2/19_Type_Casting.md)。 -> 类型转换运算符语法 +> 类型转换运算符语法 > -> *类型转换运算符* → **is** [*类型*](03_Types.md#type) -> *类型转换运算符* → **as** [*类型*](03_Types.md#type) -> *类型转换运算符* → **as** **?** [*类型*](03_Types.md#type) -> *类型转换运算符* → **as** **!** [*类型*](03_Types.md#type) +> *类型转换运算符* → **is** [*类型*](03_Types.md#type) +> *类型转换运算符* → **as** [*类型*](03_Types.md#type) +> *类型转换运算符* → **as** **?** [*类型*](03_Types.md#type) +> *类型转换运算符* → **as** **!** [*类型*](03_Types.md#type) ## 基本表达式 @@ -230,16 +230,16 @@ f(x as Any) > 基本表达式语法 > -> *基本表达式* → [*标识符*](02_Lexical_Structure.md#identifier) [*泛型实参子句*](08_Generic_Parameters_and_Arguments.md#generic-argument-clause)可选 -> *基本表达式* → [*字面量表达式*](#literal-expression) -> *基本表达式* → [*self 表达式*](#self-expression) -> *基本表达式* → [*超类表达式*](#superclass-expression) -> *基本表达式* → [*闭包表达式*](#closure-expression) -> *基本表达式* → [*圆括号表达式*](#parenthesized-expression) -> *基本表达式* → [*隐式成员表达式*](#implicit-member-expression) -> *基本表达式* → [*通配符表达式*](#wildcard-expression) -> *基本表达式* → [*选择器表达式*](#selector-expression) -> *基本表达式* → [*key-path字符串表达式*](#key-patch-string-expression) +> *基本表达式* → [*标识符*](02_Lexical_Structure.md#identifier) [*泛型实参子句*](08_Generic_Parameters_and_Arguments.md#generic-argument-clause)可选 +> *基本表达式* → [*字面量表达式*](#literal-expression) +> *基本表达式* → [*self 表达式*](#self-expression) +> *基本表达式* → [*超类表达式*](#superclass-expression) +> *基本表达式* → [*闭包表达式*](#closure-expression) +> *基本表达式* → [*圆括号表达式*](#parenthesized-expression) +> *基本表达式* → [*隐式成员表达式*](#implicit-member-expression) +> *基本表达式* → [*通配符表达式*](#wildcard-expression) +> *基本表达式* → [*选择器表达式*](#selector-expression) +> *基本表达式* → [*key-path字符串表达式*](#key-patch-string-expression) ### 字面量表达式 @@ -263,7 +263,7 @@ func logFunctionName(string: String = #function) { print(string) } func myFunction() { - logFunctionName() + logFunctionName() } myFunction() // 打印 “myFunction()” ``` @@ -291,23 +291,23 @@ var emptyDictionary: [String : Double] = [:] > 字面量表达式语法 > -> *字面量表达式* → [*字面量*](02_Lexical_Structure.md#literal) -> *字面量表达式* → [*数组字面量*](#array-literal) | [*字典字面量*](#dictionary-literal) | [*练习场字面量*](#playground-literal) -> *字面量表达式* → **#file** | **#line** | **#column** | **#function** +> *字面量表达式* → [*字面量*](02_Lexical_Structure.md#literal) +> *字面量表达式* → [*数组字面量*](#array-literal) | [*字典字面量*](#dictionary-literal) | [*练习场字面量*](#playground-literal) +> *字面量表达式* → **#file** | **#line** | **#column** | **#function** > -> *数组字面量* → [[*数组字面量项列表*](#array-literal-items)可选 **]** +> *数组字面量* → [[*数组字面量项列表*](#array-literal-items)可选 **]** -> *数组字面量项列表* → [*数组字面量项*](#array-literal-item) **,**可选 | [*数组字面量项*](#array-literal-item) **,** [*数组字面量项列表*](#array-literal-items) +> *数组字面量项列表* → [*数组字面量项*](#array-literal-item) **,**可选 | [*数组字面量项*](#array-literal-item) **,** [*数组字面量项列表*](#array-literal-items) -> *数组字面量项* → [*表达式*](#expression) +> *数组字面量项* → [*表达式*](#expression) > -> *字典字面量* → [[*字典字面量项列表*](#dictionary-literal-items) **]** | **[** **:** **]** +> *字典字面量* → [[*字典字面量项列表*](#dictionary-literal-items) **]** | **[** **:** **]** -> *字典字面量项列表* → [*字典字面量项*](#dictionary-literal-item) **,**可选 | [*字典字面量项*](#dictionary-literal-item) **,** [*字典字面量项列表*](#dictionary-literal-items) +> *字典字面量项列表* → [*字典字面量项*](#dictionary-literal-item) **,**可选 | [*字典字面量项*](#dictionary-literal-item) **,** [*字典字面量项列表*](#dictionary-literal-items) -> *字典字面量项* → [*表达式*](#expression) **:** [*表达式*](#expression)。 +> *字典字面量项* → [*表达式*](#expression) **:** [*表达式*](#expression)。 @@ -315,11 +315,11 @@ var emptyDictionary: [String : Double] = [:] `self` 表达式是对当前类型或者当前实例的显式引用,它有如下形式: -> self -> self.`成员名称` -> self[`下标索引`] -> self(`构造器参数`) -> self.init(`构造器参数`) +> self +> self.`成员名称` +> self[`下标索引`] +> self(`构造器参数`) +> self.init(`构造器参数`) 如果在构造器、下标、实例方法中,`self` 引用的是当前类型的实例。在一个类型方法中,`self` 引用的是当前的类型。 @@ -345,42 +345,42 @@ struct Point { } ``` -> Self 表达式语法 +> Self 表达式语法 > -> *self 表达式* → **self** | [*self 方法表达式*](#self-method-expression) | [*self 下标表达式*](#self-subscript-expression) | [*self 构造器表达式*](#self-initializer-expression) +> *self 表达式* → **self** | [*self 方法表达式*](#self-method-expression) | [*self 下标表达式*](#self-subscript-expression) | [*self 构造器表达式*](#self-initializer-expression) > -> *self 方法表达式* → **self** **.** [*标识符*](02_Lexical_Structure.md#identifier) +> *self 方法表达式* → **self** **.** [*标识符*](02_Lexical_Structure.md#identifier) -> *self 下标表达式* → **self** [ [*函数调用参数表*](#function-call-argument-list­) **]** - -> *self 构造器表达式* → **self** **.** **init** +> *self 下标表达式* → **self** [ [*函数调用参数表*](#function-call-argument-list­) **]** + +> *self 构造器表达式* → **self** **.** **init** ### 父类表达式 *父类*表达式可以使我们在某个类中访问它的超类,它有如下形式: -> super.`成员名称` -> super[`下标索引`] -> super.init(`构造器参数`) +> super.`成员名称` +> super[`下标索引`] +> super.init(`构造器参数`) 第一种形式用来访问超类的某个成员,第二种形式用来访问超类的下标,第三种形式用来访问超类的构造器。 子类可以通过超类表达式在它们的成员、下标和构造器中使用超类中的实现。 -> 父类表达式语法 +> 父类表达式语法 > -> *超类表达式* → [*超类方法表达式*](#superclass-method-expression) | [*超类下标表达式*](#superclass-subscript-expression) | [*超类构造器表达式*](#superclass-initializer-expression) +> *超类表达式* → [*超类方法表达式*](#superclass-method-expression) | [*超类下标表达式*](#superclass-subscript-expression) | [*超类构造器表达式*](#superclass-initializer-expression) > -> *超类方法表达式* → **super** **.** [*标识符*](02_Lexical_Structure.md#identifier) +> *超类方法表达式* → **super** **.** [*标识符*](02_Lexical_Structure.md#identifier) -> *超类下标表达式* → **super** [[*函数调用参数表*](#function-call-argument-list­) **]** +> *超类下标表达式* → **super** [[*函数调用参数表*](#function-call-argument-list­) **]** -> *超类构造器表达式* → **super** **.** **init** +> *超类构造器表达式* → **super** **.** **init** ### 闭包表达式 @@ -484,24 +484,24 @@ myFunction { [weak parent = self.parent] in print(parent!.title) } > 闭包表达式语法 > -> *闭包表达式* → **{** [*闭包签名*](#closure-signature)可选 [*语句*](#statements) **}** +> *闭包表达式* → **{** [*闭包签名*](#closure-signature)可选 [*语句*](#statements) **}** -> *闭包签名* → [*参数子句*](#parameter-clause) [*函数结果*](05_Declarations.html#function-result)可选 **in** -> *闭包签名* → [*标识符列表*](#identifier-list) [*函数结果*](05_Declarations.md#function-result)可选 **in** -> *闭包签名* → [*捕获列表*](#capture-list) [*参数子句*](05_Declarations.md#parameter-clause) [*函数结果*](05_Declarations.md#function-result)可选 **in** -> *闭包签名* → [*捕获列表*](#capture-list) [*标识符列表*](02_Lexical_Structure.md#identifier-list) [*函数结果*](05_Declarations.md#function-result)可选 **in** -> *闭包签名* → [*捕获列表*](#capture-list) **in** +> *闭包签名* → [*参数子句*](#parameter-clause) [*函数结果*](05_Declarations.html#function-result)可选 **in** +> *闭包签名* → [*标识符列表*](#identifier-list) [*函数结果*](05_Declarations.md#function-result)可选 **in** +> *闭包签名* → [*捕获列表*](#capture-list) [*参数子句*](05_Declarations.md#parameter-clause) [*函数结果*](05_Declarations.md#function-result)可选 **in** +> *闭包签名* → [*捕获列表*](#capture-list) [*标识符列表*](02_Lexical_Structure.md#identifier-list) [*函数结果*](05_Declarations.md#function-result)可选 **in** +> *闭包签名* → [*捕获列表*](#capture-list) **in** -> *捕获列表* → [ [*捕获列表项列表*](#capture-list-items) **]** +> *捕获列表* → [ [*捕获列表项列表*](#capture-list-items) **]** -> *捕获列表项列表* → [*捕获列表项*](#capture-list-item) | [*捕获列表项*](#capture-list-item) **,** [*捕获列表项列表*](#capture-list-items) +> *捕获列表项列表* → [*捕获列表项*](#capture-list-item) | [*捕获列表项*](#capture-list-item) **,** [*捕获列表项列表*](#capture-list-items) -> *捕获列表项* → [*捕获说明符*](#capture-specifier)可选 [*表达式*](#expression) +> *捕获列表项* → [*捕获说明符*](#capture-specifier)可选 [*表达式*](#expression) > *捕获说明符* → **weak** | **unowned** | **unowned(safe)** | **unowned(unsafe)** - + ### 隐式成员表达式 @@ -516,10 +516,10 @@ var x = MyEnumeration.SomeValue x = .AnotherValue ``` -> 隐式成员表达式语法 +> 隐式成员表达式语法 > -> *隐式成员表达式* → **.** [*标识符*](02_Lexical_Structure.md#identifier) +> *隐式成员表达式* → **.** [*标识符*](02_Lexical_Structure.md#identifier) ### 圆括号表达式 @@ -529,7 +529,7 @@ x = .AnotherValue > 圆括号表达式语法 > -> *圆括号表达式* → **( [*表达式*](#expression) )** +> *圆括号表达式* → **( [*表达式*](#expression) )** ### 元组表达式 @@ -543,11 +543,11 @@ x = .AnotherValue > 元组表达式语法 > -> *元组表达式* → **( )** | **(**[*元组元素*](#tuple-element), [*元组元素列表*](#tuple-element-list) **)** +> *元组表达式* → **( )** | **(**[*元组元素*](#tuple-element), [*元组元素列表*](#tuple-element-list) **)** -> *元组元素列表* → [*元组元素*](#tuple-element) | [*元组元素*](#tuple-element) **,** [*元组元素列表*](#tuple-element-list) +> *元组元素列表* → [*元组元素*](#tuple-element) | [*元组元素*](#tuple-element) **,** [*元组元素列表*](#tuple-element-list) -> *元组元素* → [*表达式*](#expression) | [*标识符*](identifier) **:** [*表达式*](#expression) +> *元组元素* → [*表达式*](#expression) | [*标识符*](identifier) **:** [*表达式*](#expression) ### 通配符表达式 @@ -559,7 +559,7 @@ x = .AnotherValue // x 为 10,20 被忽略 ``` -> 通配符表达式语法 +> 通配符表达式语法 > > *通配符表达式* → **_** @@ -626,16 +626,16 @@ let anotherSelector = #selector(SomeClass.doSomething(_:) as (SomeClass) -> (Str > 后缀表达式语法 -> *后缀表达式* → [*基本表达式*](#primary-expression) -> *后缀表达式* → [*后缀表达式*](#postfix-expression) [*后缀运算符*](02_Lexical_Structure.md#postfix-operator) -> *后缀表达式* → [*函数调用表达式*](#function-call-expression) -> *后缀表达式* → [*构造器表达式*](#initializer-expression) -> *后缀表达式* → [*显式成员表达式*](#explicit-member-expression) -> *后缀表达式* → [*后缀 self 表达式*](#postfix-self-expression) -> *后缀表达式* → [*dynamicType 表达式*](#dynamic-type-expression) -> *后缀表达式* → [*下标表达式*](#subscript-expression) -> *后缀表达式* → [*强制取值表达式*](#forced-value-expression) -> *后缀表达式* → [*可选链表达式*](#optional-chaining-expression) +> *后缀表达式* → [*基本表达式*](#primary-expression) +> *后缀表达式* → [*后缀表达式*](#postfix-expression) [*后缀运算符*](02_Lexical_Structure.md#postfix-operator) +> *后缀表达式* → [*函数调用表达式*](#function-call-expression) +> *后缀表达式* → [*构造器表达式*](#initializer-expression) +> *后缀表达式* → [*显式成员表达式*](#explicit-member-expression) +> *后缀表达式* → [*后缀 self 表达式*](#postfix-self-expression) +> *后缀表达式* → [*dynamicType 表达式*](#dynamic-type-expression) +> *后缀表达式* → [*下标表达式*](#subscript-expression) +> *后缀表达式* → [*强制取值表达式*](#forced-value-expression) +> *后缀表达式* → [*可选链表达式*](#optional-chaining-expression) ### 函数调用表达式 @@ -668,10 +668,10 @@ myData.someMethod {$0 == 13} > 函数调用表达式语法 -> *函数调用表达式* → [*后缀表达式*](#postfix-expression) [*圆括号表达式*](#parenthesized-expression) -> *函数调用表达式* → [*后缀表达式*](#postfix-expression) [*圆括号表达式*](#parenthesized-expression)可选 [*尾随闭包*](#trailing-closure) +> *函数调用表达式* → [*后缀表达式*](#postfix-expression) [*圆括号表达式*](#parenthesized-expression) +> *函数调用表达式* → [*后缀表达式*](#postfix-expression) [*圆括号表达式*](#parenthesized-expression)可选 [*尾随闭包*](#trailing-closure) -> *尾随闭包* → [*闭包表达式*](#closure-expression) +> *尾随闭包* → [*闭包表达式*](#closure-expression) ### 构造器表达式 @@ -713,8 +713,8 @@ let s3 = someValue.dynamicType.init(data: 7) // 有效 > 构造器表达式语法 -> *构造器表达式* → [*后缀表达式*](#postfix-expression) **.** **init** -> *构造器表达式* → [*后缀表达式*](#postfix-expression) **.** **init** **(** [*参数名称*](#argument-names) **)** +> *构造器表达式* → [*后缀表达式*](#postfix-expression) **.** **init** +> *构造器表达式* → [*后缀表达式*](#postfix-expression) **.** **init** **(** [*参数名称*](#argument-names) **)** ### 显式成员表达式 @@ -773,14 +773,14 @@ let x = [10, 3, 20, 15, 4] > 显式成员表达式语法 -> *显式成员表达式* → [*后缀表达式*](#postfix-expression) **.** [*十进制数字*] (02_Lexical_Structure.html#decimal-digit) +> *显式成员表达式* → [*后缀表达式*](#postfix-expression) **.** [*十进制数字*] (02_Lexical_Structure.html#decimal-digit) > *显式成员表达式* → [*后缀表达式*](#postfix-expression) **.** [*标识符*](02_Lexical_Structure.html#identifier) [*泛型实参子句*](08_Generic_Parameters_and_Arguments.html#generic-argument-clause)可选
-> *显式成员表达式* → [*后缀表达式*](#postfix-expression) **.** [*标识符*] (02_Lexical_Structure.html#identifier) **(** [*参数名称*](#argument-names) **)** -> +> *显式成员表达式* → [*后缀表达式*](#postfix-expression) **.** [*标识符*] (02_Lexical_Structure.html#identifier) **(** [*参数名称*](#argument-names) **)** +> > *参数名称* → [*参数名*](#argument-name) [*参数名称*](#argument-names)可选
-> *参数名* → [*标识符*](02_Lexical_Structure.html#identifier) **:** +> *参数名* → [*标识符*](02_Lexical_Structure.html#identifier) **:** ### 后缀 self 表达式 @@ -794,7 +794,7 @@ let x = [10, 3, 20, 15, 4] 第二种形式返回相应的类型。我们可以用它来获取某个实例的类型作为一个值来使用。例如,`SomeClass.self` 会返回 `SomeClass` 类型本身,你可以将其传递给相应函数或者方法作为参数。 -> 后缀 self 表达式语法 +> 后缀 self 表达式语法 > > *后缀 self 表达式* → [*后缀表达式*](#postfix-expression) **.** **self** @@ -811,7 +811,7 @@ let x = [10, 3, 20, 15, 4] 关于下标的声明,请参阅 [协议下标声明](05_Declarations.html#protocol_subscript_declaration)。 -> 下标表达式语法 +> 下标表达式语法 > > *下标表达式* → [*后缀表达式*](#postfix-expression) **[** [*表达式列表*](#expression-list) **]** @@ -831,13 +831,13 @@ let x = [10, 3, 20, 15, 4] var x: Int? = 0 x!++ // x 现在是 1 - + var someDictionary = ["a": [1, 2, 3], "b": [10, 20]] someDictionary["a"]![0] = 100 -// someDictionary 现在是 [b: [10, 20], a: [100, 2, 3]] +// someDictionary 现在是 [b: [10, 20], a: [100, 2, 3]] ``` -> 强制取值语法 +> 强制取值语法 > > *强制取值表达式* → [*后缀表达式*](#postfix-expression) **!** @@ -874,8 +874,8 @@ if let unwrappedC = c { ```swift func someFunctionWithSideEffects() -> Int { // 译者注:为了能看出此函数是否被执行,加上了一句打印 - print("someFunctionWithSideEffects") - return 42 + print("someFunctionWithSideEffects") + return 42 } var someDictionary = ["a": [1, 2, 3], "b": [10, 20]] @@ -888,7 +888,7 @@ someDictionary["a"]?[0] = someFunctionWithSideEffects() // someDictionary 现在是 ["b": [10, 20], "a": [42, 2, 3]] ``` -> 可选链表达式语法 +> 可选链表达式语法 > > *可选链表达式* → [*后缀表达式*](#postfix-expression) **?** diff --git a/source/chapter3/05_Statements.md b/source/chapter3/05_Statements.md index 8b498341..9164a274 100755 --- a/source/chapter3/05_Statements.md +++ b/source/chapter3/05_Statements.md @@ -21,11 +21,11 @@ 本页包含内容: - [循环语句](#loop_statements) - - [For-In 语句](#for-in_statements) + - [For-In 语句](#for-in_statements) - [While 语句](#while_statements) - [Repeat-While 语句](#repeat-while_statements) - [分支语句](#branch_statements) - - [If 语句](#if_statements) + - [If 语句](#if_statements) - [Guard 语句](#guard_statements) - [Switch 语句](#switch_statements) - [带标签的语句](#labeled_statements) @@ -38,7 +38,7 @@ - [Defer 语句](#defer_statements) - [Do 语句](#do_statements) - [编译器控制语句](#compiler_control_statements) - - [编译配置语句](#build_config_statements) + - [编译配置语句](#build_config_statements) - [行控制语句](#line_control_statements) - [可用性条件](#availability_condition) @@ -50,17 +50,17 @@ > 语句语法 -> *语句* → [*表达式*](04_Expressions.md#expression) **;**可选 -> *语句* → [*声明*](05_Declarations.md#declaration) **;**可选 -> *语句* → [*循环语句*](#loop-statement) **;**可选 -> *语句* → [*分支语句*](#branch-statement) **;**可选 -> *语句* → [*带标签的语句*](#labeled-statement) **;**可选 -> *语句* → [*控制转移语句*](#control-transfer-statement) **;**可选 -> *语句* → [*defer 语句*](#defer-statement) **;**可选 -> *语句* → [*do 语句*](#do-statement) **:**可选 -> *语句* → [*编译器控制语句*](#compiler-control-statement) +> *语句* → [*表达式*](04_Expressions.md#expression) **;**可选 +> *语句* → [*声明*](05_Declarations.md#declaration) **;**可选 +> *语句* → [*循环语句*](#loop-statement) **;**可选 +> *语句* → [*分支语句*](#branch-statement) **;**可选 +> *语句* → [*带标签的语句*](#labeled-statement) **;**可选 +> *语句* → [*控制转移语句*](#control-transfer-statement) **;**可选 +> *语句* → [*defer 语句*](#defer-statement) **;**可选 +> *语句* → [*do 语句*](#do-statement) **:**可选 +> *语句* → [*编译器控制语句*](#compiler-control-statement) -> *多条语句* → [*语句*](#statement) [*多条语句*](#statements)可选 +> *多条语句* → [*语句*](#statement) [*多条语句*](#statements)可选 ## 循环语句 @@ -69,12 +69,12 @@ 通过 `break` 语句和 `continue` 语句可以改变循环语句的控制流。有关这两条语句,详情参见 [Break 语句](#break_statement) 和 [Continue 语句](#continue_statement)。 -> 循环语句语法 +> 循环语句语法 > -> *循环语句* → [*for-in 语句*](#for-in-statement) -> *循环语句* → [*while 语句*](#while-statement) -> *循环语句* → [*repeat-while 语句*](#repeat-while-statement) +> *循环语句* → [*for-in 语句*](#for-in-statement) +> *循环语句* → [*while 语句*](#while-statement) +> *循环语句* → [*repeat-while 语句*](#repeat-while-statement) ### For-In 语句 @@ -91,7 +91,7 @@ for item in collection { `for-in` 语句在循环开始前会调用集合表达式的 `generate()` 方法来获取一个实现了 `GeneratorType` 协议的类型的值。接下来循环开始,反复调用该值的 `next()` 方法。如果其返回值不是 `None`,它将会被赋给“项”,然后执行循环体语句,执行完毕后回到循环开始处,继续重复这一过程;否则,既不会赋值也不会执行循环体语句,`for-in` 语句至此执行完毕。 -> for-in 语句语法 +> for-in 语句语法 > > *for-in 语句* → **for** **case**可选 [*模式*](07_Patterns.md#pattern) **in** [*表达式*](04_Expressions.md#expression) [*where 子句*](#where-clause)可选 [*代码块*](05_Declarations.md#code-block) @@ -124,14 +124,14 @@ while condition { > *while 语句* → **while** [*条件子句*](#condition-clause) [*代码块*](05_Declarations.md#code-block) -> *条件子句* → [*表达式*](04_Expressions.md#expression) | [*表达式*](04_Expressions.md#expression) **,** [*条件列表*](#condition-list) +> *条件子句* → [*表达式*](04_Expressions.md#expression) | [*表达式*](04_Expressions.md#expression) **,** [*条件列表*](#condition-list) -> *条件* → [*表达式*](04_Expressions.md#expression) |[*可用性条件*](#availability-condition) | [*case 条件*](#case-condition) | [*可选绑定条件*](#optional-binding-condition) -> +> *条件* → [*表达式*](04_Expressions.md#expression) |[*可用性条件*](#availability-condition) | [*case 条件*](#case-condition) | [*可选绑定条件*](#optional-binding-condition) +> -> *case 条件* → **case** [*模式*](07_Patterns.md#pattern) [*构造器*](05_Declarations.md#initializer) +> *case 条件* → **case** [*模式*](07_Patterns.md#pattern) [*构造器*](05_Declarations.md#initializer) -> *可选绑定条件* → **let** [*模式*](07_Patterns.md#pattern) [*构造器*](05_Declarations.md#initializer) | **var** [*模式*](07_Patterns.md#pattern) [*构造器*](05_Declarations.md#initializer) +> *可选绑定条件* → **let** [*模式*](07_Patterns.md#pattern) [*构造器*](05_Declarations.md#initializer) | **var** [*模式*](07_Patterns.md#pattern) [*构造器*](05_Declarations.md#initializer) ### Repeat-While 语句 @@ -143,7 +143,7 @@ while condition { ```swift repeat { statements -} while condition +} while condition ``` `repeat-while` 语句的执行流程如下: @@ -158,7 +158,7 @@ repeat { > repeat-while 语句语法 > -> *repeat-while 语句* → **repeat** [*代码块*](05_Declarations.md#code-block) **while** [*表达式*](04_Expressions.md#expression) +> *repeat-while 语句* → **repeat** [*代码块*](05_Declarations.md#code-block) **while** [*表达式*](04_Expressions.md#expression) ## 分支语句 @@ -170,9 +170,9 @@ repeat { > 分支语句语法 > -> *分支语句* → [*if 语句*](#if-statement) -> *分支语句* → [*guard 语句*](#guard-statement) -> *分支语句* → [*switch 语句*](#switch-statement) +> *分支语句* → [*if 语句*](#if-statement) +> *分支语句* → [*guard 语句*](#guard-statement) +> *分支语句* → [*switch 语句*](#switch-statement) ### If 语句 @@ -213,44 +213,44 @@ if condition 1 { `if` 语句中条件的结果必须是 Bool 类型或者 Bool 的桥接类型。另外,条件语句也可以使用可选绑定,请参阅 [可选绑定](../chapter2/01_The_Basics.md#optional_binding)。 -> if 语句语法 +> if 语句语法 > -> *if 语句* → **if** [*条件子句*](#condition-clause) [*代码块*](05_Declarations.md#code-block) [*else 子句*](#else-clause)可选 +> *if 语句* → **if** [*条件子句*](#condition-clause) [*代码块*](05_Declarations.md#code-block) [*else 子句*](#else-clause)可选 -> *else 子句* → **else** [*代码块*](05_Declarations.md#code-block) | **else** [*if 语句*](#if-statement) +> *else 子句* → **else** [*代码块*](05_Declarations.md#code-block) | **else** [*if 语句*](#if-statement) ### Guard 语句 - + 如果一个或者多个条件不成立,可用 `guard` 语句用来退出当前作用域。 `guard` 语句的格式如下: ```swift guard condition else { - statements + statements } ``` `guard` 语句中条件的结果必须是 Bool 类型或者 Bool 的桥接类型。另外,条件也可以是一条可选绑定,请参阅 [可选绑定](../chapter2/01_The_Basics.html#optional_binding)。 - + 在 `guard` 语句中进行可选绑定的常量或者变量,其可用范围从声明开始直到作用域结束。 - + `guard` 语句必须有 `else` 子句,而且必须在该子句中调用 `Never` 返回类型的函数,或者使用下面的语句退出当前作用域: - + * `return` * `break` * `continue` * `throw` - + 关于控制转移语句,请参阅 [控制转移语句](#control_transfer_statements)。关于 `Never` 返回类型的函数,请参阅 [永不返回的函数](05_Declarations.md#rethrowing_functions_and_methods)。 > guard 语句语法 > -> *guard 语句* → **guard** [*条件子句*](#condition-clause) **else** [*代码块*] (05_Declarations.html#code-block) - +> *guard 语句* → **guard** [*条件子句*](#condition-clause) **else** [*代码块*] (05_Declarations.html#code-block) + ### Switch 语句 @@ -269,7 +269,7 @@ case pattern 3 where condition, statements default: statements -} +} ``` `switch` 语句会先计算*控制表达式*的值,然后与每一个 `case` 的模式进行匹配。如果匹配成功,程序将会执行对应的 `case` 中的语句。另外,每一个 `case` 都不能为空,也就是说在每一个 `case` 中必须至少有一条语句。如果你不想在匹配到的 `case` 中执行代码,只需在该 `case` 中写一条 `break` 语句即可。 @@ -299,21 +299,21 @@ case let (x, y) where x == y: > switch 语句语法 > -> *switch 语句* → **switch** [*表达式*](04_Expressions.html#expression) **{** [*switch-case 列表*](#switch-cases)可选 **}** +> *switch 语句* → **switch** [*表达式*](04_Expressions.html#expression) **{** [*switch-case 列表*](#switch-cases)可选 **}** -> *switch case 列表* → [*switch-case*](#switch-case) [*switch-case 列表*](#switch-cases)可选 +> *switch case 列表* → [*switch-case*](#switch-case) [*switch-case 列表*](#switch-cases)可选 -> *switch case* → [*case 标签*](#case-label) [*多条语句*](#statements) | [*default 标签*](#default-label) [*多条语句*](#statements) +> *switch case* → [*case 标签*](#case-label) [*多条语句*](#statements) | [*default 标签*](#default-label) [*多条语句*](#statements) -> *case 标签* → **case** [*case 项列表*](#case-item-list) **:** +> *case 标签* → **case** [*case 项列表*](#case-item-list) **:** -> *case 项列表* → [*模式*](07_Patterns.md#pattern) [*where 子句*](#where-clause)可选 | [*模式*](07_Patterns.md#pattern) [*where 子句*](#where-clause)可选 **,** [*case 项列表*](#case-item-list) +> *case 项列表* → [*模式*](07_Patterns.md#pattern) [*where 子句*](#where-clause)可选 | [*模式*](07_Patterns.md#pattern) [*where 子句*](#where-clause)可选 **,** [*case 项列表*](#case-item-list) -> *default 标签* → **default** **:** +> *default 标签* → **default** **:** > -> *where-clause* → **where** [*where 表达式*](#where-expression) +> *where-clause* → **where** [*where 表达式*](#where-expression) > *where-expression* → [*表达式*](04_Expressions.md#expression) @@ -326,17 +326,17 @@ case let (x, y) where x == y: 关于使用带标签的语句的例子,请参阅 [控制流](../chapter2/05_Control_Flow.html) 一章中的 [带标签的语句](../chapter2/05_Control_Flow.html#labeled_statements)。 -> 带标签的语句语法 +> 带标签的语句语法 > -> *带标签的语句* → [*语句标签*](#statement-label) [*循环语句*](#loop-statement) -> *带标签的语句* → [*语句标签*](#statement-label) [*if 语句*](#if-statement) -> *带标签的语句* → [*语句标签*](#statement-label) [*switch 语句*](#switch-statement) -> > *带标签的语句* → [*语句标签*](#statement-label) [*do 语句*](#sdo-statement) +> *带标签的语句* → [*语句标签*](#statement-label) [*循环语句*](#loop-statement) +> *带标签的语句* → [*语句标签*](#statement-label) [*if 语句*](#if-statement) +> *带标签的语句* → [*语句标签*](#statement-label) [*switch 语句*](#switch-statement) +> > *带标签的语句* → [*语句标签*](#statement-label) [*do 语句*](#sdo-statement) -> *语句标签* → [*标签名称*](#label-name) **:** +> *语句标签* → [*标签名称*](#label-name) **:** -> *标签名称* → [*标识符*](02_Lexical_Structure.md#identifier) +> *标签名称* → [*标识符*](02_Lexical_Structure.md#identifier) ## 控制转移语句 @@ -346,11 +346,11 @@ case let (x, y) where x == y: > 控制转移语句语法 > -> *控制转移语句* → [*break 语句*](#break-statement) -> *控制转移语句* → [*continue 语句*](#continue-statement) -> *控制转移语句* → [*fallthrough 语句*](#fallthrough-statement) -> *控制转移语句* → [*return 语句*](#return-statement) -> *控制转移语句* → [*throw 语句*](#throw-statement) +> *控制转移语句* → [*break 语句*](#break-statement) +> *控制转移语句* → [*continue 语句*](#continue-statement) +> *控制转移语句* → [*fallthrough 语句*](#fallthrough-statement) +> *控制转移语句* → [*return 语句*](#return-statement) +> *控制转移语句* → [*throw 语句*](#throw-statement) ### Break 语句 @@ -368,10 +368,10 @@ case let (x, y) where x == y: 关于使用 `break` 语句的例子,请参阅 [控制流](../chapter2/05_Control_Flow.html) 一章的 [Break](../chapter2/05_Control_Flow.html#break) 和 [带标签的语句](../chapter2/05_Control_Flow.html#labeled_statements)。 -> break 语句语法 +> break 语句语法 > -> *break 语句* → **break** [*标签名称*](#label-name)可选 +> *break 语句* → **break** [*标签名称*](#label-name)可选 ### Continue 语句 @@ -391,7 +391,7 @@ case let (x, y) where x == y: 关于使用 `continue` 语句的例子,请参阅 [控制流](../chapter2/05_Control_Flow.html) 一章的 [Continue](../chapter2/05_Control_Flow.html#continue) 和 [带标签的语句](../chapter2/05_Control_Flow.html#labeled_statements)。 -> continue 语句语法 +> continue 语句语法 > > *continue 语句* → **continue** [*标签名称*](#label-name)可选 @@ -422,22 +422,22 @@ case let (x, y) where x == y: 当 `return` 语句后面带表达式时,表达式的值将会返回给调用函数或方法。如果表达式的值的类型与函数或者方法声明的返回类型不匹配,Swift 则会在返回表达式的值之前将表达式的值的类型转换为返回类型。 -> 注意 +> 注意 > > 正如 [可失败构造器](05_Declarations.html#failable_initializers) 中所描述的,`return nil` 在可失败构造器中用于表明构造失败。 而只写 `return` 时,仅仅是从该函数或方法中返回,而不返回任何值(也就是说,函数或方法的返回类型为 `Void` 或者说 `()`)。 -> return 语句语法 +> return 语句语法 > > *return 语句* → **return** [*表达式*](04_Expressions.html#expression)可选 - + ### Throw 语句 `throw` 语句出现在抛出函数或者抛出方法体内,或者类型被 `throws` 关键字标记的闭包表达式体内。 - + `throw` 语句使程序在当前作用域结束执行,并向外围作用域传播错误。抛出的错误会一直传递,直到被 `do` 语句的 `catch` 子句处理掉。 `throw` 语句由 `throw` 关键字紧跟一个表达式组成,如下所示: @@ -448,7 +448,7 @@ case let (x, y) where x == y: 关于如何使用 `throw` 语句的例子,请参阅 [错误处理](../chapter2/18_Error_Handling.html) 一章的 [用 throwing 函数传递错误](../chapter2/18_Error_Handling.html#propagating_errors_using_throwing_functions)。 -> throw 语句语法 +> throw 语句语法 > > *throw 语句* → **throw** [*表达式*](04_Expressions.html#expression) @@ -515,24 +515,24 @@ do { 关于如何在 `do` 语句中使用一系列 `catch` 子句的例子,请参阅 [错误处理](../chapter2/17_Error_Handling.html#handling_errors)。 -> do 语句语法 +> do 语句语法 > -> *do 语句* → **do** [*代码块*](05_Declarations.html#code-block) [*多条 catch 子句*](#catch-clauses)可选 +> *do 语句* → **do** [*代码块*](05_Declarations.html#code-block) [*多条 catch 子句*](#catch-clauses)可选 -> *多条 catch 子句* → [*catch 子句*](#catch-clause) [*多条 catch 子句*](#catch-clauses)可选 +> *多条 catch 子句* → [*catch 子句*](#catch-clause) [*多条 catch 子句*](#catch-clauses)可选 -> *catch 子句* → **catch** [*模式*](07_Patterns.html#pattern)可选 [*where 子句*](#where-clause)可选 [*代码块*](05_Declarations.html#code-block) +> *catch 子句* → **catch** [*模式*](07_Patterns.html#pattern)可选 [*where 子句*](#where-clause)可选 [*代码块*](05_Declarations.html#code-block) ## 编译器控制语句 编译器控制语句允许程序改变编译器的行为。Swift 有两种编译器控制语句:编译配置语句和线路控制语句。 -> 编译器控制语句语法 +> 编译器控制语句语法 > -> *编译器控制语句* → [*编译配置语句*](#build-config-statement) +> *编译器控制语句* → [*编译配置语句*](#build-config-statement) > *编译器控制语句* → [*线路控制语句*](#line-control-statement) @@ -560,7 +560,7 @@ statements `swift()`(语言版本检测函数)的版本号参数主要由主版本号和次版本号组成并且使用点号(`.`)分隔开,`>=` 和版本号之间不能有空格。 -> 注意 +> 注意 > > `arch(arm)` 平台检测函数在 ARM 64 位设备上不会返回 `true`。如果代码在 32 位的 iOS 模拟器上编译,`arch(i386)` 平台检测函数会返回 `true`。 @@ -578,7 +578,7 @@ statements to compile if both compilation conditions are false #endif ``` -> 注意 +> 注意 > > 即使没有被编译,编译配置中的语句仍然会被解析。然而,唯一的例外是编译配置语句中包含语言版本检测函数:仅当 `Swift` 编译器版本和语言版本检测函数中指定的版本号匹配时,语句才会被解析。这种设定能确保旧的编译器不会尝试去解析新 Swift 版本的语法。 @@ -586,35 +586,35 @@ statements to compile if both compilation conditions are false > 编译配置语句语法 > -> *单个编译配置语句* → **if** [*编译配置*](#build-configuration) [*语句*](#statements)可选 [*多个编译配置 elseif 子句*](#build-configuration-elseif-clauses)可选 **-** [*单个编译配置 else 子句*](#build-configuration-else-clause)可选 **#endif** +> *单个编译配置语句* → **if** [*编译配置*](#build-configuration) [*语句*](#statements)可选 [*多个编译配置 elseif 子句*](#build-configuration-elseif-clauses)可选 **-** [*单个编译配置 else 子句*](#build-configuration-else-clause)可选 **#endif** -> *多个编译配置 elseif 子句* → [*单个编译配置 elseif 子句*](#build-configuration-elseif-clause) [*多个编译配置 elseif 子句*](build-configuration-elseif-clauses)可选 +> *多个编译配置 elseif 子句* → [*单个编译配置 elseif 子句*](#build-configuration-elseif-clause) [*多个编译配置 elseif 子句*](build-configuration-elseif-clauses)可选 -> *单个编译配置 elseif 子句* → **#elseif** [*编译配置*](#build-configuration) [*语句*](#statements)可选 +> *单个编译配置 elseif 子句* → **#elseif** [*编译配置*](#build-configuration) [*语句*](#statements)可选 -> *单个编译配置 else 子句* → **#else** [*语句*](#statements)可选 +> *单个编译配置 else 子句* → **#else** [*语句*](#statements)可选 -> *编译配置* → [*平台检测函数*](#platform-testing-function) -> *编译配置* → [*语言版本检测函数*](#language-version-testing-function) -> *编译配置* → [*标识符*](02_Lexical_Structure.md#identifier) -> *编译配置* → [*布尔值字面量*](02_Lexical_Structure.md#boolean-literal) -> *编译配置* → **(** [*编译配置*](#build-configuration) **)** -> *编译配置* → **!** [*编译配置*](#build-configuration) -> *编译配置* → [*编译配置*](#build-configuration) **&&** [*编译配置*](#build-configuration) -> *编译配置* → [*编译配置*](#build-configuration) **||** [*编译配置*](#build-configuration) +> *编译配置* → [*平台检测函数*](#platform-testing-function) +> *编译配置* → [*语言版本检测函数*](#language-version-testing-function) +> *编译配置* → [*标识符*](02_Lexical_Structure.md#identifier) +> *编译配置* → [*布尔值字面量*](02_Lexical_Structure.md#boolean-literal) +> *编译配置* → **(** [*编译配置*](#build-configuration) **)** +> *编译配置* → **!** [*编译配置*](#build-configuration) +> *编译配置* → [*编译配置*](#build-configuration) **&&** [*编译配置*](#build-configuration) +> *编译配置* → [*编译配置*](#build-configuration) **||** [*编译配置*](#build-configuration) -> *平台检测函数* → **os** **(** [*操作系统*](#operating-system) **)** -> *平台检测函数* → **arch** **(** [*架构*](#architecture) **)** +> *平台检测函数* → **os** **(** [*操作系统*](#operating-system) **)** +> *平台检测函数* → **arch** **(** [*架构*](#architecture) **)** -> *语言版本检测函数* → **swift** **(** **>=** [*swift 版本*](#swift-version) **)** +> *语言版本检测函数* → **swift** **(** **>=** [*swift 版本*](#swift-version) **)** -> *操作系统* → **OSX** | **iOS** | **watchOS** | **tvOS** +> *操作系统* → **OSX** | **iOS** | **watchOS** | **tvOS** -> *架构* → **i386** | **x86_64** | **arm** | **arm64** +> *架构* → **i386** | **x86_64** | **arm** | **arm64** -> *swift 版本* → [*十进制数字*](02_Lexical_Structure.md#decimal-digit) ­**.** ­[*十进制数字*](02_Lexical_Structure.md#decimal-digit) +> *swift 版本* → [*十进制数字*](02_Lexical_Structure.md#decimal-digit) ­**.** ­[*十进制数字*](02_Lexical_Structure.md#decimal-digit) ### 行控制语句 @@ -634,12 +634,12 @@ statements to compile if both compilation conditions are false > 行控制语句语法 > -> *行控制语句* → **#sourceLocation(file:[*文件名*](#file-name),line:[*行号*](#line-number))** -> *行控制语句* → **#sourceLocation()** +> *行控制语句* → **#sourceLocation(file:[*文件名*](#file-name),line:[*行号*](#line-number))** +> *行控制语句* → **#sourceLocation()** -> *行号* → 大于 0 的十进制整数 +> *行号* → 大于 0 的十进制整数 -> *文件名* → [*静态字符串字面量*](02_Lexical_Structure.md#static-string-literal) +> *文件名* → [*静态字符串字面量*](02_Lexical_Structure.md#static-string-literal) ### 可用性条件 @@ -659,25 +659,25 @@ if #available(platform name version, ..., *) { 使用可用性条件来执行一个代码块时,取决于使用的 API 在运行时是否可用,编译器会根据可用性条件提供的信息来决定是否执行相应的代码块。 可用性条件使用一系列逗号分隔的平台名称和版本。使用 `iOS`,`OSX`,以及 `watchOS` 等作为平台名称,并写上相应的版本号。`*` 参数是必须写的,用于处理未来的潜在平台。可用性条件确保了运行时的平台不低于条件中指定的平台版本时才执行代码块。 - -与布尔类型的条件不同,不能用逻辑运算符 `&&` 和 `||` 组合可用性条件。 + +与布尔类型的条件不同,不能用逻辑运算符 `&&` 和 `||` 组合可用性条件。 > 可用性条件语法 > -> *可用性条件* → **#available** **(** [*可用性参数列表*](#availability-arguments) **)** +> *可用性条件* → **#available** **(** [*可用性参数列表*](#availability-arguments) **)** -> *可用性参数列表* → [*可用性参数*](#availability-argument) | [*可用性参数*](#availability-argument) **,** [*可用性参数列表*](#availability-arguments) +> *可用性参数列表* → [*可用性参数*](#availability-argument) | [*可用性参数*](#availability-argument) **,** [*可用性参数列表*](#availability-arguments) -> *可用性参数* → [平台名称](#platform-name) [平台版本](#platform-version) -> *可用性条件* → __*__ +> *可用性参数* → [平台名称](#platform-name) [平台版本](#platform-version) +> *可用性条件* → __*__ > -> *平台名称* → **iOS** | **iOSApplicationExtension** -> *平台名称* → **OSX** | **macOSApplicationExtension** -> *平台名称* → **watchOS** -> *平台名称* → **tvOS** +> *平台名称* → **iOS** | **iOSApplicationExtension** +> *平台名称* → **OSX** | **macOSApplicationExtension** +> *平台名称* → **watchOS** +> *平台名称* → **tvOS** -> *平台版本* → [十进制数字](02_Lexical_Structure.md#decimal-digits) -> *平台版本* → [十进制数字](02_Lexical_Structure.md#decimal-digits) **.** [十进制数字](02_Lexical_Structure.md#decimal-digits) -> *平台版本* → [十进制数字](02_Lexical_Structure.md#decimal-digits) **.** [十进制数字](02_Lexical_Structure.md#decimal-digits) **.** [十进制数字](02_Lexical_Structure.md#decimal-digits) +> *平台版本* → [十进制数字](02_Lexical_Structure.md#decimal-digits) +> *平台版本* → [十进制数字](02_Lexical_Structure.md#decimal-digits) **.** [十进制数字](02_Lexical_Structure.md#decimal-digits) +> *平台版本* → [十进制数字](02_Lexical_Structure.md#decimal-digits) **.** [十进制数字](02_Lexical_Structure.md#decimal-digits) **.** [十进制数字](02_Lexical_Structure.md#decimal-digits) diff --git a/source/chapter3/06_Declarations.md b/source/chapter3/06_Declarations.md index 6856184c..35d92fd8 100755 --- a/source/chapter3/06_Declarations.md +++ b/source/chapter3/06_Declarations.md @@ -10,7 +10,7 @@ > 翻译+校对:[Lenhoon](https://github.com/Lenhoon), > [BridgeQ](https://github.com/WXGBridgeQ) -> 2.1 +> 2.1 > 翻译:[mmoaay](https://github.com/mmoaay), [shanks](http://codebuild.me) > 校对:[shanks](http://codebuild.me) @@ -70,22 +70,22 @@ > 声明语法 > -> *声明* → [*导入声明*](#import-declaration) -> *声明* → [*常量声明*](#constant-declaration) -> *声明* → [*变量声明*](#variable-declaration) -> *声明* → [*类型别名声明*](#typealias-declaration) -> *声明* → [*函数声明*](#function-declaration) -> *声明* → [*枚举声明*](#enum-declaration) -> *声明* → [*结构体声明*](#struct-declaration) -> *声明* → [*类声明*](#class-declaration) -> *声明* → [*协议声明*](#protocol-declaration) -> *声明* → [*构造器声明*](#initializer-declaration) -> *声明* → [*析构器声明*](#deinitializer-declaration) -> *声明* → [*扩展声明*](#extension-declaration) -> *声明* → [*下标声明*](#subscript-declaration) -> *声明* → [*运算符声明*](#operator-declaration) +> *声明* → [*导入声明*](#import-declaration) +> *声明* → [*常量声明*](#constant-declaration) +> *声明* → [*变量声明*](#variable-declaration) +> *声明* → [*类型别名声明*](#typealias-declaration) +> *声明* → [*函数声明*](#function-declaration) +> *声明* → [*枚举声明*](#enum-declaration) +> *声明* → [*结构体声明*](#struct-declaration) +> *声明* → [*类声明*](#class-declaration) +> *声明* → [*协议声明*](#protocol-declaration) +> *声明* → [*构造器声明*](#initializer-declaration) +> *声明* → [*析构器声明*](#deinitializer-declaration) +> *声明* → [*扩展声明*](#extension-declaration) +> *声明* → [*下标声明*](#subscript-declaration) +> *声明* → [*运算符声明*](#operator-declaration) > -> *多条声明* → [*声明*](#declaration) [*多条声明*](#declarations)可选 +> *多条声明* → [*声明*](#declaration) [*多条声明*](#declarations)可选 ## 顶级代码 @@ -134,14 +134,14 @@ import 模块.子模块 > 导入声明语法 > > -> *导入声明* → [*特性列表*](06_Attributes.html#attributes)可选 **import** [*导入类型*](#import-kind)可选 [*导入路径*](#import-path) -> +> *导入声明* → [*特性列表*](06_Attributes.html#attributes)可选 **import** [*导入类型*](#import-kind)可选 [*导入路径*](#import-path) +> > -> *导入类型* → **typealias** | **struct** | **class** | **enum** | **protocol** | **let** | **var** | **func** +> *导入类型* → **typealias** | **struct** | **class** | **enum** | **protocol** | **let** | **var** | **func** > -> *导入路径* → [*导入路径标识符*](#import-path-identifier) | [*导入路径标识符*](#import-path-identifier) **.** [*导入路径*](#import-path) +> *导入路径* → [*导入路径标识符*](#import-path-identifier) | [*导入路径标识符*](#import-path-identifier) **.** [*导入路径*](#import-path) > -> *导入路径标识符* → [*标识符*](02_Lexical_Structure.html#identifier) | [*运算符*](02_Lexical_Structure.html#operator) +> *导入路径标识符* → [*标识符*](02_Lexical_Structure.html#identifier) | [*运算符*](02_Lexical_Structure.html#operator) ## 常量声明 @@ -181,13 +181,13 @@ print("The second number is \(secondNumber).") > 常量声明语法 > > -> *常量声明* → [*特性列表*](06_Attributes.html#attributes)可选 [*声明修饰符列表*](#declaration-modifiers)可选 **let** [*模式构造器列表*](pattern-initializer-list) +> *常量声明* → [*特性列表*](06_Attributes.html#attributes)可选 [*声明修饰符列表*](#declaration-modifiers)可选 **let** [*模式构造器列表*](pattern-initializer-list) > -> *模式构造器列表* → [*模式构造器*](#pattern-initializer) | [*模式构造器*](#pattern-initializer) **,** [*模式构造器列表*](#pattern-initializer-list) +> *模式构造器列表* → [*模式构造器*](#pattern-initializer) | [*模式构造器*](#pattern-initializer) **,** [*模式构造器列表*](#pattern-initializer-list) > -> *模式构造器* → [*模式*](07_Patterns.html#pattern) [*构造器*](#initializer)可选 +> *模式构造器* → [*模式*](07_Patterns.html#pattern) [*构造器*](#initializer)可选 > -> *构造器* → **=** [*表达式*](04_Expressions.html#expression) +> *构造器* → **=** [*表达式*](04_Expressions.html#expression) ## 变量声明 @@ -291,44 +291,44 @@ var 变量名称: 类型 = 表达式 { > 变量声明语法 > -> *变量声明* → [*变量声明头*](#variable-declaration-head) [*模式构造器列表*](#pattern-initializer-list) -> *变量声明* → [*变量声明头*](#variable-declaration-head) [*变量名称*](#variable-name) [*类型标注*](03_Types.html#type-annotation) [*代码块*](#code-block) -> *变量声明* → [*变量声明头*](#variable-declaration-head) [*变量名称*](#variable-name) [*类型标注*](03_Types.html#type-annotation) [*getter-setter 代码块*](#getter-setter-block) -> *变量声明* → [*变量声明头*](#variable-declaration-head) [*变量名称*](#variable-name) [*类型标注*](03_Types.html#type-annotation) [*getter-setter 关键字代码块*](#getter-setter-keyword-block) -> *变量声明* → [*变量声明头*](#variable-declaration-head) [*变量名称*](#variable-name) [*构造器*](#initializer) [*willSet-didSet 代码块*](#willSet-didSet-block) -> *变量声明* → [*变量声明头*](#variable-declaration-head) [*变量名称*](#variable-name) [*类型标注*](03_Types.html#type-annotation) [*构造器*](#initializer)可选 [*willSet-didSet 代码块*](#willSet-didSet-block) +> *变量声明* → [*变量声明头*](#variable-declaration-head) [*模式构造器列表*](#pattern-initializer-list) +> *变量声明* → [*变量声明头*](#variable-declaration-head) [*变量名称*](#variable-name) [*类型标注*](03_Types.html#type-annotation) [*代码块*](#code-block) +> *变量声明* → [*变量声明头*](#variable-declaration-head) [*变量名称*](#variable-name) [*类型标注*](03_Types.html#type-annotation) [*getter-setter 代码块*](#getter-setter-block) +> *变量声明* → [*变量声明头*](#variable-declaration-head) [*变量名称*](#variable-name) [*类型标注*](03_Types.html#type-annotation) [*getter-setter 关键字代码块*](#getter-setter-keyword-block) +> *变量声明* → [*变量声明头*](#variable-declaration-head) [*变量名称*](#variable-name) [*构造器*](#initializer) [*willSet-didSet 代码块*](#willSet-didSet-block) +> *变量声明* → [*变量声明头*](#variable-declaration-head) [*变量名称*](#variable-name) [*类型标注*](03_Types.html#type-annotation) [*构造器*](#initializer)可选 [*willSet-didSet 代码块*](#willSet-didSet-block) -> *变量声明头* → [*特性列表*](06_Attributes.html#attributes)可选 [*声明修饰符列表*](#declaration-modifiers)可选 **var** +> *变量声明头* → [*特性列表*](06_Attributes.html#attributes)可选 [*声明修饰符列表*](#declaration-modifiers)可选 **var** > -> *变量名称* → [*标识符*](02_Lexical_Structure.html#identifier) +> *变量名称* → [*标识符*](02_Lexical_Structure.html#identifier) -> *getter-setter 代码块* → [*代码块*](#code-block) -> *getter-setter 代码块* → **{** [*getter 子句*](#getter-clause) [*setter 子句*](#setter-clause)可选 **}** -> *getter-setter 代码块* → **{** [*setter 子句*](#setter-clause) [*getter 子句*](#getter-clause) **}** +> *getter-setter 代码块* → [*代码块*](#code-block) +> *getter-setter 代码块* → **{** [*getter 子句*](#getter-clause) [*setter 子句*](#setter-clause)可选 **}** +> *getter-setter 代码块* → **{** [*setter 子句*](#setter-clause) [*getter 子句*](#getter-clause) **}** > -> *getter 子句* → [*特性列表*](06_Attributes.html#attributes)可选 **get** [*代码块*](#code-block) +> *getter 子句* → [*特性列表*](06_Attributes.html#attributes)可选 **get** [*代码块*](#code-block) > -> *setter 子句* → [*特性列表*](06_Attributes.html#attributes)可选 **set** [*setter 名称*](#setter-name)可选 [*代码块*](#code-block) +> *setter 子句* → [*特性列表*](06_Attributes.html#attributes)可选 **set** [*setter 名称*](#setter-name)可选 [*代码块*](#code-block) > -> *setter 名称* → **(** [*标识符*](02_Lexical_Structure.html#identifier) **)** +> *setter 名称* → **(** [*标识符*](02_Lexical_Structure.html#identifier) **)** -> *getter-setter 关键字代码块* → **{** [*getter 关键字子句*](#getter-keyword-clause) [*setter 关键字子句*](#setter-keyword-clause)可选 **}** -> *getter-setter 关键字代码块* → **{** [*setter 关键字子句*](#setter-keyword-clause) [*getter 关键字子句*](#getter-keyword-clause) **}** +> *getter-setter 关键字代码块* → **{** [*getter 关键字子句*](#getter-keyword-clause) [*setter 关键字子句*](#setter-keyword-clause)可选 **}** +> *getter-setter 关键字代码块* → **{** [*setter 关键字子句*](#setter-keyword-clause) [*getter 关键字子句*](#getter-keyword-clause) **}** > -> *getter 关键字子句* → [*特性列表*](06_Attributes.html#attributes)可选 **get** +> *getter 关键字子句* → [*特性列表*](06_Attributes.html#attributes)可选 **get** > -> *setter 关键字子句* → [*特性列表*](06_Attributes.html#attributes)可选 **set** +> *setter 关键字子句* → [*特性列表*](06_Attributes.html#attributes)可选 **set** -> *willSet-didSet 代码块* → **{** [*willSet 子句*](#willSet-clause) [*didSet 子句*](#didSet-clause)可选 **}** -> *willSet-didSet 代码块* → **{** [*didSet 子句*](#didSet-clause) [*willSet 子句*](#willSet-clause)可选 **}** +> *willSet-didSet 代码块* → **{** [*willSet 子句*](#willSet-clause) [*didSet 子句*](#didSet-clause)可选 **}** +> *willSet-didSet 代码块* → **{** [*didSet 子句*](#didSet-clause) [*willSet 子句*](#willSet-clause)可选 **}** > -> *willSet 子句* → [*特性列表*](06_Attributes.html#attributes)可选 **willSet** [*setter 名称*](#setter-name)可选 [*代码块*](#code-block) +> *willSet 子句* → [*特性列表*](06_Attributes.html#attributes)可选 **willSet** [*setter 名称*](#setter-name)可选 [*代码块*](#code-block) > -> *didSet 子句* → [*特性列表*](06_Attributes.html#attributes)可选 **didSet** [*setter 名称*](#setter-name)可选 [*代码块*](#code-block) +> *didSet 子句* → [*特性列表*](06_Attributes.html#attributes)可选 **didSet** [*setter 名称*](#setter-name)可选 [*代码块*](#code-block) ## 类型别名声明 @@ -344,7 +344,7 @@ typealias 类型别名 = 现存类型 ```swift typealias StringDictionary = Dictionary - + // 下列两个字典拥有同样的类型 var dictionary1: StringDictionary = [:] var dictionary2: Dictionary = [:] @@ -364,7 +364,7 @@ protocol Sequence { associatedtype Iterator: IteratorProtocol typealias Element = Iterator.Element } - + func sum(_ sequence: T) -> Int where T.Element == Int { // ... } @@ -378,13 +378,13 @@ func sum(_ sequence: T) -> Int where T.Element == Int { > 类型别名声明语法 > > -> *类型别名声明* → [*类型别名头*](#typealias-head) [*类型别名赋值*](#typealias-assignment) +> *类型别名声明* → [*类型别名头*](#typealias-head) [*类型别名赋值*](#typealias-assignment) > -> *类型别名头* → [*特性列表*](06_Attributes.html#attributes)可选 [*访问级别修饰符*](#access-level-modifier)可选 **typealias** [*类型别名名称*](#typealias-name) +> *类型别名头* → [*特性列表*](06_Attributes.html#attributes)可选 [*访问级别修饰符*](#access-level-modifier)可选 **typealias** [*类型别名名称*](#typealias-name) > -> *类型别名名称* → [*标识符*](02_Lexical_Structure.html#identifier) +> *类型别名名称* → [*标识符*](02_Lexical_Structure.html#identifier) > -> *类型别名赋值* → **=** [*类型*](03_Types.html#type) +> *类型别名赋值* → **=** [*类型*](03_Types.html#type) ## 函数声明 @@ -393,7 +393,7 @@ func sum(_ sequence: T) -> Int where T.Element == Int { ```swift func 函数名称(参数列表) -> 返回类型 { - 语句 + 语句 } ``` @@ -565,37 +565,37 @@ Swift 定义了 `Never` 类型,它表示函数或者方法不会返回给它 > 函数声明语法 > -> *函数声明* → [*函数头*](#function-head) [*函数名*](#function-name) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [*函数签名*](#function-signature) [*函数体*](#function-body)可选 +> *函数声明* → [*函数头*](#function-head) [*函数名*](#function-name) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [*函数签名*](#function-signature) [*函数体*](#function-body)可选 -> *函数头* → [*特性列表*](06_Attributes.html#attributes)可选 [*声明修饰符列表*](#declaration-modifiers)可选 **func** +> *函数头* → [*特性列表*](06_Attributes.html#attributes)可选 [*声明修饰符列表*](#declaration-modifiers)可选 **func** > -> *函数名* → [*标识符*](02_Lexical_Structure.html#identifier) | [*运算符*](02_Lexical_Structure.html#operator) +> *函数名* → [*标识符*](02_Lexical_Structure.html#identifier) | [*运算符*](02_Lexical_Structure.html#operator) -> *函数签名* → [*参数子句列表*](#parameter-clauses) **throws**可选 [*函数结果*](#function-result)可选 -> *函数签名* → [*参数子句列表*](#parameter-clauses) **rethrows** [*函数结果*](#function-result)可选 +> *函数签名* → [*参数子句列表*](#parameter-clauses) **throws**可选 [*函数结果*](#function-result)可选 +> *函数签名* → [*参数子句列表*](#parameter-clauses) **rethrows** [*函数结果*](#function-result)可选 > -> *函数结果* → **->** [*特性列表*](06_Attributes.html#attributes)可选 [*类型*](03_Types.html#type) +> *函数结果* → **->** [*特性列表*](06_Attributes.html#attributes)可选 [*类型*](03_Types.html#type) > -> *函数体* → [*代码块*](#code-block) +> *函数体* → [*代码块*](#code-block) -> *参数子句列表* → [*参数子句*](#parameter-clause) [*参数子句列表*](#parameter-clauses)可选 +> *参数子句列表* → [*参数子句*](#parameter-clause) [*参数子句列表*](#parameter-clauses)可选 > -> *参数子句* → **(** **)** | **(** [*参数列表*](#parameter-list) **)** +> *参数子句* → **(** **)** | **(** [*参数列表*](#parameter-list) **)** > -> *参数列表* → [*参数*](#parameter) | [*参数*](#parameter) **,** [*参数列表*](#parameter-list) +> *参数列表* → [*参数*](#parameter) | [*参数*](#parameter) **,** [*参数列表*](#parameter-list) > -> *参数* → **let**可选 [*外部参数名*](#external-parameter-name)可选 [*内部参数名*](#local-parameter-name) [*类型标注*](03_Types.html#type-annotation) [*默认参数子句*](#default-argument-clause)可选 -> *参数* → **inout** [*外部参数名*](#external-parameter-name)可选 [*内部参数名*](#local-parameter-name) [*类型标注*](03_Types.html#type-annotation) -> *参数* → [*外部参数名*](#external-parameter-name)可选 [*内部参数名*](#local-parameter-name) [*类型标注*](03_Types.html#type-annotation) **...** +> *参数* → **let**可选 [*外部参数名*](#external-parameter-name)可选 [*内部参数名*](#local-parameter-name) [*类型标注*](03_Types.html#type-annotation) [*默认参数子句*](#default-argument-clause)可选 +> *参数* → **inout** [*外部参数名*](#external-parameter-name)可选 [*内部参数名*](#local-parameter-name) [*类型标注*](03_Types.html#type-annotation) +> *参数* → [*外部参数名*](#external-parameter-name)可选 [*内部参数名*](#local-parameter-name) [*类型标注*](03_Types.html#type-annotation) **...** > -> *外部参数名* → [*标识符*](02_Lexical_Structure.html#identifier) | **_** +> *外部参数名* → [*标识符*](02_Lexical_Structure.html#identifier) | **_** > -> *内部参数名* → [*标识符*](02_Lexical_Structure.html#identifier) | **_** +> *内部参数名* → [*标识符*](02_Lexical_Structure.html#identifier) | **_** > -> *默认参数子句* → **=** [*表达式*](04_Expressions.html#expression) +> *默认参数子句* → **=** [*表达式*](04_Expressions.html#expression) ## 枚举声明 @@ -707,45 +707,45 @@ enum WeekendDay: String { 可以使用 `switch` 语句来检验枚举用例的值,正如 [使用 switch 语句匹配枚举值](../chapter2/08_Enumerations.html#matching_enumeration_values_with_a_switch_statement) 所述。枚举类型是模式匹配的,依靠 `switch` 语句 `case` 块中的枚举用例模式,正如 [枚举用例模式](07_Patterns.html#enumeration_case_pattern) 所述。 -> 枚举声明语法 +> 枚举声明语法 > -> *枚举声明* → [*特性列表*](06_Attributes.html#attributes)可选 [*访问级别修饰符*](#access-level-modifier)可选 [*联合风格枚举*](#union-style-enum) -> *枚举声明* → [*特性列表*](06_Attributes.html#attributes)可选 [*访问级别修饰符*](#access-level-modifier) 可选 [*原始值风格枚举*](#raw-value-style-enum) +> *枚举声明* → [*特性列表*](06_Attributes.html#attributes)可选 [*访问级别修饰符*](#access-level-modifier)可选 [*联合风格枚举*](#union-style-enum) +> *枚举声明* → [*特性列表*](06_Attributes.html#attributes)可选 [*访问级别修饰符*](#access-level-modifier) 可选 [*原始值风格枚举*](#raw-value-style-enum) -> *联合风格枚举* → **indirect**可选 **enum** [*枚举名称*](#enum-name) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [类型继承子句](03_Types.html#type-inheritance-clause)可选 **{** [*多个联合风格枚举成员*](#union-style-enum-members)可选 **}** +> *联合风格枚举* → **indirect**可选 **enum** [*枚举名称*](#enum-name) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [类型继承子句](03_Types.html#type-inheritance-clause)可选 **{** [*多个联合风格枚举成员*](#union-style-enum-members)可选 **}** > -> *多个联合风格枚举成员* → [*联合风格枚举成员*](#union-style-enum-member) [*多个联合风格枚举成员*](#union-style-enum-members)可选 +> *多个联合风格枚举成员* → [*联合风格枚举成员*](#union-style-enum-member) [*多个联合风格枚举成员*](#union-style-enum-members)可选 > -> *联合风格枚举成员* → [*声明*](#declaration) | [*联合风格枚举用例子句*](#union-style-enum-case-clause) +> *联合风格枚举成员* → [*声明*](#declaration) | [*联合风格枚举用例子句*](#union-style-enum-case-clause) > -> *联合风格枚举用例子句* → [*特性列表*](06_Attributes.html#attributes)可选 **indirect**可选 **case** [*联合风格枚举用例列表*](#union-style-enum-case-list) +> *联合风格枚举用例子句* → [*特性列表*](06_Attributes.html#attributes)可选 **indirect**可选 **case** [*联合风格枚举用例列表*](#union-style-enum-case-list) > -> *联合风格枚举用例列表* → [*联合风格枚举用例*](#union-style-enum-case) | [*联合风格枚举用例*](#union-style-enum-case) **,** [*联合风格枚举用例列表*](#union-style-enum-case-list) +> *联合风格枚举用例列表* → [*联合风格枚举用例*](#union-style-enum-case) | [*联合风格枚举用例*](#union-style-enum-case) **,** [*联合风格枚举用例列表*](#union-style-enum-case-list) > -> *联合风格枚举用例* → [*枚举用例名称*](#enum-case-name) [*元组类型*](03_Types.html#tuple-type)可选 +> *联合风格枚举用例* → [*枚举用例名称*](#enum-case-name) [*元组类型*](03_Types.html#tuple-type)可选 > -> *枚举名称* → [*标识符*](02_Lexical_Structure.html#identifier) +> *枚举名称* → [*标识符*](02_Lexical_Structure.html#identifier) > -> *枚举用例名称* → [*标识符*](02_Lexical_Structure.html#identifier) +> *枚举用例名称* → [*标识符*](02_Lexical_Structure.html#identifier) -> *原始值风格枚举* → **enum** [*枚举名称*](#enum-name) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [类型继承子句](03_Types.html#type-inheritance-clause) **{** [*多个原始值风格枚举成员*](#raw-value-style-enum-members) **}** +> *原始值风格枚举* → **enum** [*枚举名称*](#enum-name) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [类型继承子句](03_Types.html#type-inheritance-clause) **{** [*多个原始值风格枚举成员*](#raw-value-style-enum-members) **}** > -> *多个原始值风格枚举成员* → [*原始值风格枚举成员*](#raw-value-style-enum-member) [*多个原始值风格枚举成员*](#raw-value-style-enum-members)可选 +> *多个原始值风格枚举成员* → [*原始值风格枚举成员*](#raw-value-style-enum-member) [*多个原始值风格枚举成员*](#raw-value-style-enum-members)可选 > -> *原始值风格枚举成员* → [*声明*](#declaration) | [*原始值风格枚举用例子句*](#raw-value-style-enum-case-clause) +> *原始值风格枚举成员* → [*声明*](#declaration) | [*原始值风格枚举用例子句*](#raw-value-style-enum-case-clause) > -> *原始值风格枚举用例子句* → [*特性列表*](06_Attributes.html#attributes)可选 **case** [*原始值风格枚举用例列表*](#raw-value-style-enum-case-list) +> *原始值风格枚举用例子句* → [*特性列表*](06_Attributes.html#attributes)可选 **case** [*原始值风格枚举用例列表*](#raw-value-style-enum-case-list) > -> *原始值风格枚举用例列表* → [*原始值风格枚举用例*](#raw-value-style-enum-case) | [*原始值风格枚举用例*](#raw-value-style-enum-case) **,** [*原始值风格枚举用例列表*](#raw-value-style-enum-case-list) +> *原始值风格枚举用例列表* → [*原始值风格枚举用例*](#raw-value-style-enum-case) | [*原始值风格枚举用例*](#raw-value-style-enum-case) **,** [*原始值风格枚举用例列表*](#raw-value-style-enum-case-list) > -> *原始值风格枚举用例* → [*枚举用例名称*](#enum-case-name) [*原始值赋值*](#raw-value-assignment)可选 +> *原始值风格枚举用例* → [*枚举用例名称*](#enum-case-name) [*原始值赋值*](#raw-value-assignment)可选 > -> *原始值赋值* → **=** [*原始值字面量*](#raw-value-literal) +> *原始值赋值* → **=** [*原始值字面量*](#raw-value-literal) > -> *原始值字面量* → [数字型字面量](02_Lexical_Structure.html#numeric-literal) | [字符串型字面量](02_Lexical_Structure.html#static-string-literal) | [布尔型字面量](02_Lexical_Structure.html#boolean-literal) +> *原始值字面量* → [数字型字面量](02_Lexical_Structure.html#numeric-literal) | [字符串型字面量](02_Lexical_Structure.html#static-string-literal) | [布尔型字面量](02_Lexical_Structure.html#boolean-literal) ## 结构体声明 @@ -783,11 +783,11 @@ struct 结构体名称: 采纳的协议 { > 结构体声明语法 > > -> *结构体声明* → [*特性列表*](06_Attributes.html#attributes)可选 [*访问级别修饰符*](#access-level-modifier) 可选 **struct** [*结构体名称*](#struct-name) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [类型继承子句](03_Types.html#type-inheritance-clause)可选 [*结构体主体*](#struct-body) +> *结构体声明* → [*特性列表*](06_Attributes.html#attributes)可选 [*访问级别修饰符*](#access-level-modifier) 可选 **struct** [*结构体名称*](#struct-name) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [类型继承子句](03_Types.html#type-inheritance-clause)可选 [*结构体主体*](#struct-body) > -> *结构体名称* → [*标识符*](02_Lexical_Structure.html#identifier) +> *结构体名称* → [*标识符*](02_Lexical_Structure.html#identifier) > -> *结构体主体* → **{** [*多条声明*](#declarations)可选 **}** +> *结构体主体* → **{** [*多条声明*](#declarations)可选 **}** ## 类声明 @@ -828,11 +828,11 @@ class 类名: 超类, 采纳的协议 { > 类声明语法 > > -> *类声明* → [*特性列表*](06_Attributes.html#attributes)可选 [访问级别修饰符](#access-level-modifier)可选 **class** [*类名*](#class-name) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [*类型继承子句*](03_Types.html#type-inheritance-clause)可选 [*类主体*](#class-body) +> *类声明* → [*特性列表*](06_Attributes.html#attributes)可选 [访问级别修饰符](#access-level-modifier)可选 **class** [*类名*](#class-name) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [*类型继承子句*](03_Types.html#type-inheritance-clause)可选 [*类主体*](#class-body) > -> *类名* → [*标识符*](02_Lexical_Structure.html#identifier) +> *类名* → [*标识符*](02_Lexical_Structure.html#identifier) > -> *类主体* → **{** [*多条声明*](#declarations)可选 **}** +> *类主体* → **{** [*多条声明*](#declarations)可选 **}** ## 协议声明 @@ -879,20 +879,20 @@ protocol SomeProtocol: class { > 协议声明语法 > -> *协议声明* → [*特性列表*](06_Attributes.html#attributes)可选 [访问级别修饰符](#access-level-modifier)可选 **protocol** [*协议名称*](#protocol-name) [*类型继承子句*](03_Types.html#type-inheritance-clause)可选 [*协议主体*](#protocol-body) +> *协议声明* → [*特性列表*](06_Attributes.html#attributes)可选 [访问级别修饰符](#access-level-modifier)可选 **protocol** [*协议名称*](#protocol-name) [*类型继承子句*](03_Types.html#type-inheritance-clause)可选 [*协议主体*](#protocol-body) > -> *协议名称* → [*标识符*](02_Lexical_Structure.html#identifier) +> *协议名称* → [*标识符*](02_Lexical_Structure.html#identifier) > -> *协议主体* → **{** [*协议成员声明列表*](#protocol-member-declarations)可选 **}** +> *协议主体* → **{** [*协议成员声明列表*](#protocol-member-declarations)可选 **}** > -> *协议成员声明* → [*协议属性声明*](#protocol-property-declaration) -> *协议成员声明* → [*协议方法声明*](#protocol-method-declaration) -> *协议成员声明* → [*协议构造器声明*](#protocol-initializer-declaration) -> *协议成员声明* → [*协议下标声明*](#protocol-subscript-declaration) -> *协议成员声明* → [*协议关联类型声明*](#protocol-associated-type-declaration) +> *协议成员声明* → [*协议属性声明*](#protocol-property-declaration) +> *协议成员声明* → [*协议方法声明*](#protocol-method-declaration) +> *协议成员声明* → [*协议构造器声明*](#protocol-initializer-declaration) +> *协议成员声明* → [*协议下标声明*](#protocol-subscript-declaration) +> *协议成员声明* → [*协议关联类型声明*](#protocol-associated-type-declaration) > -> *协议成员声明列表* → [*协议成员声明*](#protocol-member-declaration) [*协议成员声明列表*](#protocol-member-declarations)可选 +> *协议成员声明列表* → [*协议成员声明*](#protocol-member-declaration) [*协议成员声明列表*](#protocol-member-declarations)可选 ### 协议属性声明 @@ -913,7 +913,7 @@ var 属性名: 类型 { get set } > 协议属性声明语法 > > -> *协议属性声明* → [*变量声明头*](#variable-declaration-head) [*变量名称*](#variable-name) [*类型标注*](03_Types.html#type-annotation) [*getter-setter 关键字代码块*](#getter-setter-keyword-block) +> *协议属性声明* → [*变量声明头*](#variable-declaration-head) [*变量名称*](#variable-name) [*类型标注*](03_Types.html#type-annotation) [*getter-setter 关键字代码块*](#getter-setter-keyword-block) ### 协议方法声明 @@ -928,7 +928,7 @@ var 属性名: 类型 { get set } > 协议方法声明语法 > > -> *协议方法声明* → [*函数头*](#function-head) [*函数名*](#function-name) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [*函数签名*](#function-signature) +> *协议方法声明* → [*函数头*](#function-head) [*函数名*](#function-name) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [*函数签名*](#function-signature) ### 协议构造器声明 @@ -946,8 +946,8 @@ var 属性名: 类型 { get set } > 协议构造器声明语法 > > -> *协议构造器声明* → [*构造器头*](#initializer-head) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [*参数子句*](#parameter-clause) **throws**可选 -> *协议构造器声明* → [*构造器头*](#initializer-head) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [*参数子句*](#parameter-clause) **rethrows** +> *协议构造器声明* → [*构造器头*](#initializer-head) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [*参数子句*](#parameter-clause) **throws**可选 +> *协议构造器声明* → [*构造器头*](#initializer-head) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [*参数子句*](#parameter-clause) **rethrows** ### 协议下标声明 @@ -978,7 +978,7 @@ subscript (参数列表) -> 返回类型 { get set } > 协议关联类型声明语法 > > -> *协议关联类型声明* → [*类型别名头*](#typealias-head) [*类型继承子句*](03_Types.html#type-inheritance-clause)可选 [*类型别名赋值*](#typealias-assignment)可选 +> *协议关联类型声明* → [*类型别名头*](#typealias-head) [*类型继承子句*](03_Types.html#type-inheritance-clause)可选 [*类型别名赋值*](#typealias-assignment)可选 ## 构造器声明 @@ -1070,14 +1070,14 @@ if let actualInstance = SomeStruct(input: "Hello") { > 构造器声明语法 > > -> *构造器声明* → [*构造器头*](#initializer-head) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [*参数子句*](#parameter-clause) **throws**可选 [*构造器主体*](#initializer-body) -> *构造器声明* → [*构造器头*](#initializer-head) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [*参数子句*](#parameter-clause) **rethrows**可选 [*构造器主体*](#initializer-body) +> *构造器声明* → [*构造器头*](#initializer-head) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [*参数子句*](#parameter-clause) **throws**可选 [*构造器主体*](#initializer-body) +> *构造器声明* → [*构造器头*](#initializer-head) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.html#generic-parameter-clause)可选 [*参数子句*](#parameter-clause) **rethrows**可选 [*构造器主体*](#initializer-body) > -> *构造器头* → [*特性列表*](06_Attributes.html#attributes)可选 [*声明修饰符列表*](#declaration-modifiers)可选 **init** -> *构造器头* → [*特性列表*](06_Attributes.html#attributes)可选 [*声明修饰符列表*](#declaration-modifiers)可选 **init** **?** -> *构造器头* → [*特性列表*](06_Attributes.html#attributes)可选 [*声明修饰符列表*](#declaration-modifiers)可选 **init** **!** +> *构造器头* → [*特性列表*](06_Attributes.html#attributes)可选 [*声明修饰符列表*](#declaration-modifiers)可选 **init** +> *构造器头* → [*特性列表*](06_Attributes.html#attributes)可选 [*声明修饰符列表*](#declaration-modifiers)可选 **init** **?** +> *构造器头* → [*特性列表*](06_Attributes.html#attributes)可选 [*声明修饰符列表*](#declaration-modifiers)可选 **init** **!** > -> *构造器主体* → [*代码块*](#code-block) +> *构造器主体* → [*代码块*](#code-block) ## 析构器声明 @@ -1102,7 +1102,7 @@ deinit { > 析构器声明语法 > > -> *析构器声明* → [*特性列表*](06_Attributes.html#attributes)可选 **deinit** [*代码块*](#code-block) +> *析构器声明* → [*特性列表*](06_Attributes.html#attributes)可选 **deinit** [*代码块*](#code-block) ## 扩展声明 @@ -1135,12 +1135,12 @@ extension 类型名称 where 要求 { > 扩展声明语法 > > -> *扩展声明* → [特性](06_Attributes.html#type_attributes)可选 [访问级别修饰符](#access-level-modifier)可选 **extension** [*类型标识符*](03_Types.html#type-identifier) [*类型-继承-子句*](03_Types.html#type-inheritance-clause)可选 [*扩展主体*](#extension-body) +> *扩展声明* → [特性](06_Attributes.html#type_attributes)可选 [访问级别修饰符](#access-level-modifier)可选 **extension** [*类型标识符*](03_Types.html#type-identifier) [*类型-继承-子句*](03_Types.html#type-inheritance-clause)可选 [*扩展主体*](#extension-body) > -> *扩展声明* → [特性](06_Attributes.html#type_attributes)可选 [访问级别修饰符](#access-level-modifier)可选 **extension** [*类型标识符*](03_Types.html#type-identifier) [*泛型-where-子句*](03_Types.html#type-inheritance-clause) [*扩展主体*](#extension-body) -> *扩展主体* → **{** [*多条声明*](#declarations)可选 **}** -> *多条声明* → [单条声明](#subscript_declaration) [多条声明](#declarations) 可选 -> *单条声明* → [声明语句](#declarations) | [编译器-控制-语句](10_Statements.html#compiler-control-statement) +> *扩展声明* → [特性](06_Attributes.html#type_attributes)可选 [访问级别修饰符](#access-level-modifier)可选 **extension** [*类型标识符*](03_Types.html#type-identifier) [*泛型-where-子句*](03_Types.html#type-inheritance-clause) [*扩展主体*](#extension-body) +> *扩展主体* → **{** [*多条声明*](#declarations)可选 **}** +> *多条声明* → [单条声明](#subscript_declaration) [多条声明](#declarations) 可选 +> *单条声明* → [声明语句](#declarations) | [编译器-控制-语句](10_Statements.html#compiler-control-statement) ## 下标声明 @@ -1176,13 +1176,13 @@ subscript (参数列表) -> 返回类型 { > 下标声明语法 > > -> *下标声明* → [*下标头*](#subscript-head) [*下标结果*](#subscript-result) [*代码块*](#code-block) -> *下标声明* → [*下标头*](#subscript-head) [*下标结果*](#subscript-result) [*getter-setter 代码块*](#getter-setter-block) -> *下标声明* → [*下标头*](#subscript-head) [*下标结果*](#subscript-result) [*getter-setter 关键字代码块*](#getter-setter-keyword-block) +> *下标声明* → [*下标头*](#subscript-head) [*下标结果*](#subscript-result) [*代码块*](#code-block) +> *下标声明* → [*下标头*](#subscript-head) [*下标结果*](#subscript-result) [*getter-setter 代码块*](#getter-setter-block) +> *下标声明* → [*下标头*](#subscript-head) [*下标结果*](#subscript-result) [*getter-setter 关键字代码块*](#getter-setter-keyword-block) > -> *下标头* → [*特性列表*](06_Attributes.html#attributes)可选 [*声明修饰符列表*](#declaration-modifiers)可选 **subscript** [*参数子句*](#parameter-clause) +> *下标头* → [*特性列表*](06_Attributes.html#attributes)可选 [*声明修饰符列表*](#declaration-modifiers)可选 **subscript** [*参数子句*](#parameter-clause) > -> *下标结果* → **->** [*特性列表*](06_Attributes.html#attributes)可选 [*类型*](03_Types.html#type) +> *下标结果* → **->** [*特性列表*](06_Attributes.html#attributes)可选 [*类型*](03_Types.html#type) ## 运算符声明 @@ -1229,17 +1229,17 @@ postfix operator 运算符名称 {} > 运算符声明语法 > -> *运算符声明* → [*前缀运算符声明*](#prefix-operator-declaration) | [*后缀运算符声明*](#postfix-operator-declaration) | [*中缀运算符声明*](#infix-operator-declaration) +> *运算符声明* → [*前缀运算符声明*](#prefix-operator-declaration) | [*后缀运算符声明*](#postfix-operator-declaration) | [*中缀运算符声明*](#infix-operator-declaration) > -> *前缀运算符声明* → **prefix** **运算符** [*运算符*](02_Lexical_Structure.html#operator) **{** **}** +> *前缀运算符声明* → **prefix** **运算符** [*运算符*](02_Lexical_Structure.html#operator) **{** **}** > -> *后缀运算符声明* → **postfix** **运算符** [*运算符*] (02_Lexical_Structure.html#operator) **{** **}** +> *后缀运算符声明* → **postfix** **运算符** [*运算符*] (02_Lexical_Structure.html#operator) **{** **}** > > *中缀运算符声明* → **infix** **运算符** [*运算符*](02_Lexical_Structure.html#operator) **{** [*中缀运算符属性*](#infix-operator-attributes)可选 **}** > -> *中缀运算符组* → [*优先级组名称*](#precedence-group-name) +> *中缀运算符组* → [*优先级组名称*](#precedence-group-name) ## 优先级组声明 @@ -1256,7 +1256,7 @@ precedencegroup 优先级组名称{ } ``` -较低优先级组和较高优先级组的名称说明了新建的优先级组是依赖于现存的优先级组的。`lowerThan` 优先级组的属性只可以引用当前模块外的优先级组。当两个运算符为同一个操作数竞争时,比如表达式 `2 + 3 * 5`,优先级更高的运算符将优先参与运算。 +较低优先级组和较高优先级组的名称说明了新建的优先级组是依赖于现存的优先级组的。`lowerThan` 优先级组的属性只可以引用当前模块外的优先级组。当两个运算符为同一个操作数竞争时,比如表达式 `2 + 3 * 5`,优先级更高的运算符将优先参与运算。 > 注意 > @@ -1272,27 +1272,27 @@ Swift 定义了大量的优先级组来与标准库的运算符配合使用, > 优先级组声明语法 > -> *优先级组声明* → **precedence**[*优先级组名称*](#precedence-group-name){[*多优先级组属性*](#precedence-group-attributes)可选 } +> *优先级组声明* → **precedence**[*优先级组名称*](#precedence-group-name){[*多优先级组属性*](#precedence-group-attributes)可选 } -> *优先级组属性* → [*优先级组属性*](#precedence-group-attribute)[*多优先级组属性*](#precedence-group-attributes)可选 **{** **}** +> *优先级组属性* → [*优先级组属性*](#precedence-group-attribute)[*多优先级组属性*](#precedence-group-attributes)可选 **{** **}** -> *优先级组属性* → [*优先级组关系*](#precedence-group-relation) -> *优先级组属性* → [*优先级组赋值性*](#precedence-group-assignment) -> *优先级组属性* → [*优先级组相关性*](#precedence-group-associativity) +> *优先级组属性* → [*优先级组关系*](#precedence-group-relation) +> *优先级组属性* → [*优先级组赋值性*](#precedence-group-assignment) +> *优先级组属性* → [*优先级组相关性*](#precedence-group-associativity) > -> *优先级组关系* → **higherThan:**[*多优先级组名称*](#precedence-group-names) -> *优先级组关系* → **lowerThan:**[*多优先级组名称*](#precedence-group-names) +> *优先级组关系* → **higherThan:**[*多优先级组名称*](#precedence-group-names) +> *优先级组关系* → **lowerThan:**[*多优先级组名称*](#precedence-group-names) > -> *优先级组赋值* → **assignment:**[*布尔字面值*](02_Lexical_Structure.html#boolean-literal) +> *优先级组赋值* → **assignment:**[*布尔字面值*](02_Lexical_Structure.html#boolean-literal) -> *优先级组结合性* → **associativity:left** -> *优先级组结合性* → **associativity:right** -> *优先级组结合性* → **associativity:none** -> +> *优先级组结合性* → **associativity:left** +> *优先级组结合性* → **associativity:right** +> *优先级组结合性* → **associativity:none** +> -> *多优先级组名称* → [*优先级组名称*](#precedence-group-name) | [*优先级组名称*](#precedence-group-name) | [*优先级组名称*](#precedence-group-name) +> *多优先级组名称* → [*优先级组名称*](#precedence-group-name) | [*优先级组名称*](#precedence-group-name) | [*优先级组名称*](#precedence-group-name) -> *优先级组名称* →[*标识符*](02_Lexical_Structure.html#identifier) +> *优先级组名称* →[*标识符*](02_Lexical_Structure.html#identifier) ## 声明修饰符 @@ -1350,12 +1350,12 @@ Swift 提供了三个级别的访问控制:`public`、`internal` 和 `private` > 声明修饰符的语法 > -> *声明修饰符* → **class** | **convenience**| **dynamic** | **final** | **infix** | **lazy** | **mutating** | **nonmutating** | **optional** | **override** | **postfix** | **prefix** | **required** | **static** | **unowned** | **unowned ( safe )** | **unowned ( unsafe )** | **weak** -> 声明修饰符 → [*访问级别修饰符*](#access-level-modifier) +> *声明修饰符* → **class** | **convenience**| **dynamic** | **final** | **infix** | **lazy** | **mutating** | **nonmutating** | **optional** | **override** | **postfix** | **prefix** | **required** | **static** | **unowned** | **unowned ( safe )** | **unowned ( unsafe )** | **weak** +> 声明修饰符 → [*访问级别修饰符*](#access-level-modifier) > -> *声明修饰符列表* → [*声明修饰符*](#declaration-modifier) [*声明修饰符列表*](#declaration-modifiers)可选 +> *声明修饰符列表* → [*声明修饰符*](#declaration-modifier) [*声明修饰符列表*](#declaration-modifiers)可选 > -> 访问级别修饰符 → **internal** | **internal ( set )** -> 访问级别修饰符 → **private** | **private ( set )** -> 访问级别修饰符 → **public** | **public ( set )** +> 访问级别修饰符 → **internal** | **internal ( set )** +> 访问级别修饰符 → **private** | **private ( set )** +> 访问级别修饰符 → **public** | **public ( set )** diff --git a/source/chapter3/07_Attributes.md b/source/chapter3/07_Attributes.md index 1ff946b1..78be9254 100755 --- a/source/chapter3/07_Attributes.md +++ b/source/chapter3/07_Attributes.md @@ -9,8 +9,8 @@ > 翻译+校对:[KYawn](https://github.com/KYawn) > 2.1 -> 翻译:[小铁匠 Linus](https://github.com/kevin833752) - +> 翻译:[小铁匠 Linus](https://github.com/kevin833752) + > 4.1 > 翻译+校对:[mylittleswift](https://github.com/mylittleswift) @@ -218,16 +218,16 @@ convention 特性总是与下面的参数之一一起出现。 `escaping` 在函数或者方法声明上使用该特性,它表示参数将不会被存储以供延迟执行,这将确保参数不会超出函数调用的生命周期。在使用 `escaping` 声明特性的函数类型中访问属性和方法时不需要显式地使用 `self.`。关于如何使用 `escaping` 特性的例子,请参阅 [逃逸闭包](http://wiki.jikexueyuan.com/project/swift/chapter2/07_Closures.html)。 -> 特性语法 +> 特性语法 > -> *特性 *→ @ 特性名 特性参数子句可选 -> *特性名* → 标识符 -> *特性参数子句* → ( 均衡令牌列表可选 ) -> *特性列表* → 特性 特性列表可选 +> *特性 *→ @ 特性名 特性参数子句可选 +> *特性名* → 标识符 +> *特性参数子句* → ( 均衡令牌列表可选 ) +> *特性列表* → 特性 特性列表可选 > -> *均衡令牌列表* → 均衡令牌 均衡令牌列表可选 -> *均衡令牌* → ( 均衡令牌列表可选 ) -> *均衡令牌* → [ 均衡令牌列表可选 ] -> *均衡令牌* → { 均衡令牌列表可选} -> *均衡令牌* → 任意标识符,关键字,字面量或运算符 -> *均衡令牌* → 任意标点除了 (,),[,],{,或 } +> *均衡令牌列表* → 均衡令牌 均衡令牌列表可选 +> *均衡令牌* → ( 均衡令牌列表可选 ) +> *均衡令牌* → [ 均衡令牌列表可选 ] +> *均衡令牌* → { 均衡令牌列表可选} +> *均衡令牌* → 任意标识符,关键字,字面量或运算符 +> *均衡令牌* → 任意标点除了 (,),[,],{,或 } diff --git a/source/chapter3/08_Patterns.md b/source/chapter3/08_Patterns.md index ddc7f16f..7eae9596 100755 --- a/source/chapter3/08_Patterns.md +++ b/source/chapter3/08_Patterns.md @@ -10,9 +10,9 @@ > 2.1 > 翻译:[BridgeQ](https://github.com/WXGBridgeQ) - + > 4.1 -> 翻译+校对:[mylittleswift](https://github.com/mylittleswift) +> 翻译+校对:[mylittleswift](https://github.com/mylittleswift) 本页内容包括: @@ -33,17 +33,17 @@ Swift 中的模式分为两类:一种能成功匹配任何类型的值,另 第二类模式用于全模式匹配,这种情况下你试图匹配的值在运行时可能不存在。此类模式包括枚举用例模式、可选模式、表达式模式和类型转换模式。你在 `switch` 语句的 `case` 标签中,`do` 语句的 `catch` 子句中,或者在 `if`、`while`、`guard` 和 `for-in` 语句的 `case` 条件句中使用这类模式。 -> 模式语法 +> 模式语法 > -> *模式* → [*通配符模式*](#wildcard_pattern) [*类型标注*](03_Types.html#type-annotation)可选 -> *模式* → [*标识符模式*](#identifier_pattern) [*类型标注*](03_Types.html#type-annotation)可选 -> *模式* → [*值绑定模式*](#value-binding-pattern) -> *模式* → [*元组模式*](#tuple-pattern) [*类型标注*](03_Types.html#type-annotation)可选 -> *模式* → [*枚举用例模式*](#enum-case-pattern) -> *模式* → [*可选模式*](#optional-pattern) -> *模式* → [*类型转换模式*](#type-casting-pattern) -> *模式* → [*表达式模式*](#expression-pattern) +> *模式* → [*通配符模式*](#wildcard_pattern) [*类型标注*](03_Types.html#type-annotation)可选 +> *模式* → [*标识符模式*](#identifier_pattern) [*类型标注*](03_Types.html#type-annotation)可选 +> *模式* → [*值绑定模式*](#value-binding-pattern) +> *模式* → [*元组模式*](#tuple-pattern) [*类型标注*](03_Types.html#type-annotation)可选 +> *模式* → [*枚举用例模式*](#enum-case-pattern) +> *模式* → [*可选模式*](#optional-pattern) +> *模式* → [*类型转换模式*](#type-casting-pattern) +> *模式* → [*表达式模式*](#expression-pattern) ## 通配符模式(Wildcard Pattern) @@ -56,10 +56,10 @@ for _ in 1...3 { } ``` -> 通配符模式语法 +> 通配符模式语法 > -> *通配符模式* → **_** +> *通配符模式* → **_** ## 标识符模式(Identifier Pattern) @@ -74,7 +74,7 @@ let someValue = 42 如果一个变量或常量声明的左边是一个标识符模式,那么这个标识符模式是值绑定模式的子模式。 -> 标识符模式语法 +> 标识符模式语法 > > *标识符模式* → [*标识符*](02_Lexical_Structure.html#identifier) @@ -98,10 +98,10 @@ case let (x, y): 在上面这个例子中,`let` 会分配到元组模式 `(x, y)` 中的各个标识符模式。因此,`switch` 语句中 `case let (x, y):` 和 `case (let x, let y):` 的匹配效果是一样的。 -> 值绑定模式语法 +> 值绑定模式语法 > -> *值绑定模式* → **var** [*模式*](#pattern) | **let** [*模式*](#pattern) +> *值绑定模式* → **var** [*模式*](#pattern) | **let** [*模式*](#pattern) ## 元组模式 @@ -128,14 +128,14 @@ let (a) = 2 // a: Int = 2 let (a): Int = 2 // a: Int = 2 ``` -> 元组模式语法 +> 元组模式语法 > -> *元组模式* → **(** [*元组模式元素列表*](#tuple-pattern-element-list)可选 **)** +> *元组模式* → **(** [*元组模式元素列表*](#tuple-pattern-element-list)可选 **)** -> *元组模式元素列表* → [*元组模式元素*](#tuple-pattern-element) | [*元组模式元素*](#tuple-pattern-element) **,** [*元组模式元素列表*](#tuple-pattern-element-list) +> *元组模式元素列表* → [*元组模式元素*](#tuple-pattern-element) | [*元组模式元素*](#tuple-pattern-element) **,** [*元组模式元素列表*](#tuple-pattern-element-list) -> *元组模式元素* → [*模式*](#pattern) +> *元组模式元素* → [*模式*](#pattern) ## 枚举用例模式(Enumeration Case Pattern) @@ -144,10 +144,10 @@ let (a): Int = 2 // a: Int = 2 如果你准备匹配的枚举用例有任何关联的值,则相应的枚举用例模式必须指定一个包含每个关联值元素的元组模式。关于使用 `switch` 语句来匹配包含关联值的枚举用例的例子,请参阅 [关联值](../chapter2/08_Enumerations.html#associated_values)。 -> 枚举用例模式语法 +> 枚举用例模式语法 > -> *枚举用例模式* → [*类型标识*](03_Types.html#type-identifier)可选 **.** [*枚举用例名*](05_Declarations.html#enum-case-name) [*元组模式*](#tuple-pattern)可选 +> *枚举用例模式* → [*类型标识*](03_Types.html#type-identifier)可选 **.** [*枚举用例名*](05_Declarations.html#enum-case-name) [*元组模式*](#tuple-pattern)可选 ## 可选模式(Optional Pattern) @@ -182,10 +182,10 @@ for case let number? in arrayOfOptinalInts { // Found a 5 ``` -> 可选模式语法 +> 可选模式语法 > -> *可选模式* → [*标识符模式*](03_Types.html#type-identifier) **?** +> *可选模式* → [*标识符模式*](03_Types.html#type-identifier) **?** ## 类型转换模式(Type-Casting Patterns) @@ -201,14 +201,14 @@ for case let number? in arrayOfOptinalInts { 关于使用 `switch` 语句配合 `is` 模式和 `as` 模式来匹配值的例子,请参阅 [Any 和 AnyObject 的类型转换](../chapter2/18_Type_Casting.html#type_casting_for_any_and_anyobject)。 -> 类型转换模式语法 +> 类型转换模式语法 > -> *类型转换模式* → [*is 模式*](#is-pattern) | [*as 模式*](#as-pattern) +> *类型转换模式* → [*is 模式*](#is-pattern) | [*as 模式*](#as-pattern) -> *is 模式* → **is** [*类型*](03_Types.html#type) +> *is 模式* → **is** [*类型*](03_Types.html#type) -> *as 模式* → [*模式*](#pattern) **as** [*类型*](03_Types.html#type) +> *as 模式* → [*模式*](#pattern) **as** [*类型*](03_Types.html#type) ## 表达式模式(Expression Pattern) @@ -247,7 +247,7 @@ default: // 打印 “The point is at (1, 2).” ``` -> 表达式模式语法 +> 表达式模式语法 > -> *表达式模式* → [*表达式*](04_Expressions.html#expression) +> *表达式模式* → [*表达式*](04_Expressions.html#expression) diff --git a/source/chapter3/09_Generic_Parameters_and_Arguments.md b/source/chapter3/09_Generic_Parameters_and_Arguments.md index 43fad622..a37ef900 100755 --- a/source/chapter3/09_Generic_Parameters_and_Arguments.md +++ b/source/chapter3/09_Generic_Parameters_and_Arguments.md @@ -9,8 +9,8 @@ > 翻译+校对:[wardenNScaiyi](https:github.com/wardenNScaiyi) > 3.0 -> 翻译+校对:[chenmingjia](https:github.com/chenmingjia) - +> 翻译+校对:[chenmingjia](https:github.com/chenmingjia) + > 4.1 > 翻译+校对:[mylittleswift](https://github.com/mylittleswift) @@ -72,29 +72,29 @@ simpleMax(3.14159, 2.71828) // T 被推断为 Double 类型 更多关于泛型 where 从句的信息和关于泛型函数声明的例子,可以看一看 [泛型 where 子句](https://github.com/numbbbbb/the-swift-programming-language-in-chinese/blob/gh-pages/source/chapter2/22_Generics.html#where_clauses) -> 泛型形参子句语法 +> 泛型形参子句语法 > -> *泛型形参子句* → **<** [*泛型形参列表*](#generic-parameter-list) [*约束子句*](#requirement-clause)可选 **>** +> *泛型形参子句* → **<** [*泛型形参列表*](#generic-parameter-list) [*约束子句*](#requirement-clause)可选 **>** -> *泛型形参列表* → [*泛形形参*](#generic-parameter) | [*泛形形参*](#generic-parameter) **,** [*泛型形参列表*](#generic-parameter-list) +> *泛型形参列表* → [*泛形形参*](#generic-parameter) | [*泛形形参*](#generic-parameter) **,** [*泛型形参列表*](#generic-parameter-list) -> *泛形形参* → [*类型名称*](03_Types.html#type-name) -> *泛形形参* → [*类型名称*](03_Types.html#type-name) **:** [*类型标识符*](03_Types.html#type-identifier) -> *泛形形参* → [*类型名称*](03_Types.html#type-name) **:** [*协议合成类型*](03_Types.html#protocol-composition-type) +> *泛形形参* → [*类型名称*](03_Types.html#type-name) +> *泛形形参* → [*类型名称*](03_Types.html#type-name) **:** [*类型标识符*](03_Types.html#type-identifier) +> *泛形形参* → [*类型名称*](03_Types.html#type-name) **:** [*协议合成类型*](03_Types.html#protocol-composition-type) -> *约束子句* → **where** [*约束列表*](#requirement-list) +> *约束子句* → **where** [*约束列表*](#requirement-list) -> *约束列表* → [*约束*](#requirement) | [*约束*](#requirement) **,** [*约束列表*](#requirement-list) +> *约束列表* → [*约束*](#requirement) | [*约束*](#requirement) **,** [*约束列表*](#requirement-list) -> *约束* → [*一致性约束*](#conformance-requirement) | [*同类型约束*](#same-type-requirement) +> *约束* → [*一致性约束*](#conformance-requirement) | [*同类型约束*](#same-type-requirement) -> *一致性约束* → [*类型标识符*](03_Types.html#type-identifier) **:** [*类型标识符*](03_Types.html#type-identifier) -> *一致性约束* → [*类型标识符*](03_Types.html#type-identifier) **:** [*协议合成类型*](03_Types.html#protocol-composition-type) +> *一致性约束* → [*类型标识符*](03_Types.html#type-identifier) **:** [*类型标识符*](03_Types.html#type-identifier) +> *一致性约束* → [*类型标识符*](03_Types.html#type-identifier) **:** [*协议合成类型*](03_Types.html#protocol-composition-type) -> *同类型约束* → [*类型标识符*](03_Types.html#type-identifier) **==** [*类型*](03_Types.html#type) +> *同类型约束* → [*类型标识符*](03_Types.html#type-identifier) **==** [*类型*](03_Types.html#type) ## 泛型实参子句 @@ -121,11 +121,11 @@ let arrayOfArrays: Array> = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] 如 [泛型形参子句](#generic_parameter) 所述,不能用泛型实参子句来指定泛型函数或构造器的类型实参。 -> 泛型实参子句语法 +> 泛型实参子句语法 > -> *泛型实参子句* → **<** [*泛型实参列表*](#generic-argument-list) **>** +> *泛型实参子句* → **<** [*泛型实参列表*](#generic-argument-list) **>** -> *泛型实参列表* → [*泛型实参*](#generic-argument) | [*泛型实参*](#generic-argument) **,** [*泛型实参列表*](#generic-argument-list) +> *泛型实参列表* → [*泛型实参*](#generic-argument) | [*泛型实参*](#generic-argument) **,** [*泛型实参列表*](#generic-argument-list) > *泛型实参* → [*类型*](03_Types.html#type) diff --git a/source/chapter3/10_Summary_of_the_Grammar.md b/source/chapter3/10_Summary_of_the_Grammar.md index 6bee1b31..5c58e57d 100755 --- a/source/chapter3/10_Summary_of_the_Grammar.md +++ b/source/chapter3/10_Summary_of_the_Grammar.md @@ -6,10 +6,10 @@ > 校对:[xielingwang](https://github.com/xielingwang) > 2.0 -> 翻译+校对:[miaosiqi](https://github.com/miaosiqi) - +> 翻译+校对:[miaosiqi](https://github.com/miaosiqi) + > 4.1 -> 翻译+校对:[mylittleswift](https://github.com/mylittleswift) +> 翻译+校对:[mylittleswift](https://github.com/mylittleswift) 本页包含内容: @@ -25,939 +25,939 @@ ## 语句 -> 语句语法 +> 语句语法 > -> *语句* → [*表达式*](../chapter3/04_Expressions.html#expression) **;** _可选_ -> *语句* → [*声明*](../chapter3/05_Declarations.html#declaration) **;** _可选_ +> *语句* → [*表达式*](../chapter3/04_Expressions.html#expression) **;** _可选_ +> *语句* → [*声明*](../chapter3/05_Declarations.html#declaration) **;** _可选_ > *语句* → [*循环语句*](../chapter3/10_Statements.html#loop_statement) **;** _可选_ -> *语句* → [*分支语句*](../chapter3/10_Statements.html#branch_statement) **;** _可选_ -> *语句* → [*标记语句(Labeled Statement)*](../chapter3/10_Statements.html#labeled_statement) -> *语句* → [*控制转移语句*](../chapter3/10_Statements.html#control_transfer_statement) **;** _可选_ -> *语句* → [*延迟语句*](TODO) **;** _可选_ +> *语句* → [*分支语句*](../chapter3/10_Statements.html#branch_statement) **;** _可选_ +> *语句* → [*标记语句(Labeled Statement)*](../chapter3/10_Statements.html#labeled_statement) +> *语句* → [*控制转移语句*](../chapter3/10_Statements.html#control_transfer_statement) **;** _可选_ +> *语句* → [*延迟语句*](TODO) **;** _可选_ -> *语句* → [*执行语句*](TODO) **;** _可选_ +> *语句* → [*执行语句*](TODO) **;** _可选_ -> *多条语句(Statements)* → [*语句*](../chapter3/10_Statements.html#statement) [*多条语句(Statements)*](../chapter3/10_Statements.html#statements) _可选_ +> *多条语句(Statements)* → [*语句*](../chapter3/10_Statements.html#statement) [*多条语句(Statements)*](../chapter3/10_Statements.html#statements) _可选_ -> 循环语句语法 +> 循环语句语法 > -> *循环语句* → [*for 语句*](../chapter3/10_Statements.html#for_statement) -> *循环语句* → [*for-in 语句*](../chapter3/10_Statements.html#for_in_statement) -> *循环语句* → [*while 语句*](../chapter3/10_Statements.html#wheetatype 类型 ile_statement) -> *循环语句* → [*repeat-while 语句*](../chapter3/10_Statements.html#do_while_statement) +> *循环语句* → [*for 语句*](../chapter3/10_Statements.html#for_statement) +> *循环语句* → [*for-in 语句*](../chapter3/10_Statements.html#for_in_statement) +> *循环语句* → [*while 语句*](../chapter3/10_Statements.html#wheetatype 类型 ile_statement) +> *循环语句* → [*repeat-while 语句*](../chapter3/10_Statements.html#do_while_statement) -> For 循环语法 +> For 循环语法 > -> *for 语句* → **for** [*for 初始条件*](../chapter3/10_Statements.html#for_init) _可选_ **;** [*表达式*](../chapter3/04_Expressions.html#expression) _可选_ **;** [*表达式*](../chapter3/04_Expressions.html#expression) _可选_ [*代码块*](../chapter3/05_Declarations.html#code_block) -> *for 语句* → **for** **(** [*for 初始条件*](../chapter3/10_Statements.html#for_init) _可选_ **;** [*表达式*](../chapter3/04_Expressions.html#expression) _可选_ **;** [*表达式*](../chapter3/04_Expressions.html#expression) _可选_ **)** [*代码块*](../chapter3/05_Declarations.html#code_block) -> *for 初始条件* → [*变量声明*](../chapter3/05_Declarations.html#variable_declaration) | [*表达式集*](../chapter3/04_Expressions.html#expression_list) +> *for 语句* → **for** [*for 初始条件*](../chapter3/10_Statements.html#for_init) _可选_ **;** [*表达式*](../chapter3/04_Expressions.html#expression) _可选_ **;** [*表达式*](../chapter3/04_Expressions.html#expression) _可选_ [*代码块*](../chapter3/05_Declarations.html#code_block) +> *for 语句* → **for** **(** [*for 初始条件*](../chapter3/10_Statements.html#for_init) _可选_ **;** [*表达式*](../chapter3/04_Expressions.html#expression) _可选_ **;** [*表达式*](../chapter3/04_Expressions.html#expression) _可选_ **)** [*代码块*](../chapter3/05_Declarations.html#code_block) +> *for 初始条件* → [*变量声明*](../chapter3/05_Declarations.html#variable_declaration) | [*表达式集*](../chapter3/04_Expressions.html#expression_list) -> For-In 循环语法 +> For-In 循环语法 > -> *for-in 语句* → **for case** _可选_ [*模式*](../chapter3/07_Patterns.html#pattern) **in** [*表达式*](../chapter3/04_Expressions.html#expression) [*代码块*](../chapter3/05_Declarations.html#code_block) [*where 从句*](TODO) _可选_ +> *for-in 语句* → **for case** _可选_ [*模式*](../chapter3/07_Patterns.html#pattern) **in** [*表达式*](../chapter3/04_Expressions.html#expression) [*代码块*](../chapter3/05_Declarations.html#code_block) [*where 从句*](TODO) _可选_ -> While 循环语法 +> While 循环语法 > -> *while 语句* → **while** [*条件从句*](../chapter3/10_Statements.html#while_condition) [*代码块*](../chapter3/05_Declarations.html#code_block) -> *条件从句* → [*表达式*](TODO) -> *条件从句* → [*表达式*](TODO) *,* [*表达式集*]() -> *条件从句* → [*表达式集*](TODO) -> *条件从句* → [*可用条件 (availability-condition*)](TODO) *|* [*表达式集*]() -> *条件集* → [*条件*](TODO) *|* [*条件*](TODO) *,* [*条件集*]() -> *条件* → [*可用条件(availability-condition)*](TODO) *|* [*个例条件(case-condition)*](TODO) *|* [*可选绑定条件(optional-binding-condition)*](TODO) -> *个例条件(case-condition)* → **case** [*模式*](TODO) [*构造器*](TODO) [*where 从句*](TODO)_可选_ -> *可选绑定条件(optional-binding-condition)* → [*可选绑定头(optional-binding-head)*](TODO) [*可选绑定连续集(optional-binding-continuation-list)*](TODO) _可选_ [*where 从句*](TODO) _可选_ -> *可选绑定头(optional-binding-head)* → **let** [*模式 构造器*](TODO) *|* **var** [*模式 构造器*](TODO) -> *可选绑定连续集(optional-binding-contiuation-list)* → [*可选绑定连续(optional-binding-contiuation)*](TODO) *|* [*可选绑定连续(optional-binding-contiuation)*](TODO) *,* [*可选绑定连续集(optional-binding-contiuation-list)*](TODO) -> *可选绑定连续(optional-binding-continuation)* → [*模式 构造器*](TODO) *|* [*可选绑定头(optional-binding-head)*](TODO) +> *while 语句* → **while** [*条件从句*](../chapter3/10_Statements.html#while_condition) [*代码块*](../chapter3/05_Declarations.html#code_block) +> *条件从句* → [*表达式*](TODO) +> *条件从句* → [*表达式*](TODO) *,* [*表达式集*]() +> *条件从句* → [*表达式集*](TODO) +> *条件从句* → [*可用条件 (availability-condition*)](TODO) *|* [*表达式集*]() +> *条件集* → [*条件*](TODO) *|* [*条件*](TODO) *,* [*条件集*]() +> *条件* → [*可用条件(availability-condition)*](TODO) *|* [*个例条件(case-condition)*](TODO) *|* [*可选绑定条件(optional-binding-condition)*](TODO) +> *个例条件(case-condition)* → **case** [*模式*](TODO) [*构造器*](TODO) [*where 从句*](TODO)_可选_ +> *可选绑定条件(optional-binding-condition)* → [*可选绑定头(optional-binding-head)*](TODO) [*可选绑定连续集(optional-binding-continuation-list)*](TODO) _可选_ [*where 从句*](TODO) _可选_ +> *可选绑定头(optional-binding-head)* → **let** [*模式 构造器*](TODO) *|* **var** [*模式 构造器*](TODO) +> *可选绑定连续集(optional-binding-contiuation-list)* → [*可选绑定连续(optional-binding-contiuation)*](TODO) *|* [*可选绑定连续(optional-binding-contiuation)*](TODO) *,* [*可选绑定连续集(optional-binding-contiuation-list)*](TODO) +> *可选绑定连续(optional-binding-continuation)* → [*模式 构造器*](TODO) *|* [*可选绑定头(optional-binding-head)*](TODO) -> Repeat-While 语句语法 +> Repeat-While 语句语法 > -*repeat-while-statement* → **repeat** [*代码块*](TODO) **while** [*表达式*](TODO) +*repeat-while-statement* → **repeat** [*代码块*](TODO) **while** [*表达式*](TODO) -> 分支语句语法 +> 分支语句语法 > -> *分支语句* → [*if 语句*](../chapter3/10_Statements.html#if_statement) -> *分支语句* → [*guard 语句*](TODO) -> *分支语句* → [*switch 语句*](../chapter3/10_Statements.html#switch_statement) +> *分支语句* → [*if 语句*](../chapter3/10_Statements.html#if_statement) +> *分支语句* → [*guard 语句*](TODO) +> *分支语句* → [*switch 语句*](../chapter3/10_Statements.html#switch_statement) -> If 语句语法 +> If 语句语法 > -> *if 语句* → **if** [*条件从句*](TODO) [*代码块*](TODO) [*else 从句(Clause)*](TODO) _可选_ -> *else 从句(Clause)* → **else** [*代码块*](../chapter3/05_Declarations.html#code_block) | **else** [*if 语句*](../chapter3/10_Statements.html#if_statement) +> *if 语句* → **if** [*条件从句*](TODO) [*代码块*](TODO) [*else 从句(Clause)*](TODO) _可选_ +> *else 从句(Clause)* → **else** [*代码块*](../chapter3/05_Declarations.html#code_block) | **else** [*if 语句*](../chapter3/10_Statements.html#if_statement) -> Guard 语句语法 +> Guard 语句语法 > -> *guard 语句* → **guard** [*条件从句*](TODO) **else** [*代码块*](TODO) +> *guard 语句* → **guard** [*条件从句*](TODO) **else** [*代码块*](TODO) - - - -> Switch 语句语法 -> -> *switch 语句* → **switch** [*表达式*](../chapter3/04_Expressions.html#expression) **{** [*SwitchCase*](../chapter3/10_Statements.html#switch_cases) _可选_ **}** -> *SwitchCase 集* → [*SwitchCase*](../chapter3/10_Statements.html#switch_case) [*SwitchCase 集*](../chapter3/10_Statements.html#switch_cases) _可选_ -> *SwitchCase* → [*case 标签*](../chapter3/10_Statements.html#case_label) [*多条语句(Statements)*](../chapter3/10_Statements.html#statements) | [*default 标签*](../chapter3/10_Statements.html#default_label) [*多条语句(Statements)*](../chapter3/10_Statements.html#statements) -> *SwitchCase* → [*case 标签*](../chapter3/10_Statements.html#case_label) **;** | [*default 标签*](../chapter3/10_Statements.html#default_label) **;** -> *case 标签* → **case** [*case 项集*](../chapter3/10_Statements.html#case_item_list) **:** -> *case 项集* → [*模式*](../chapter3/07_Patterns.html#pattern) [*where-clause*](../chapter3/10_Statements.html#guard_clause) _可选_ | [*模式*](../chapter3/07_Patterns.html#pattern) [*where-clause*](../chapter3/10_Statements.html#guard_clause) _可选_ **,** [*case 项集*](../chapter3/10_Statements.html#case_item_list) -> *default 标签* → **default** **:** -> *where 从句* → **where** [*where 表达式*](TODO) -> *where 表达式* → [*表达式*](TODO) -> 标记语句语法 +> Switch 语句语法 > -> *标记语句(Labeled Statement)* → [*语句标签*](../chapter3/10_Statements.html#statement_label) [*循环语句*](../chapter3/10_Statements.html#loop_statement) | [*语句标签*](../chapter3/10_Statements.html#statement_label) [*if 语句*](../chapter3/10_Statements.html#switch_statement) | [*语句标签*](TODY) [*switch 语句*](TODY) -> *语句标签* → [*标签名称*](../chapter3/10_Statements.html#label_name) **:** -> *标签名称* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) +> *switch 语句* → **switch** [*表达式*](../chapter3/04_Expressions.html#expression) **{** [*SwitchCase*](../chapter3/10_Statements.html#switch_cases) _可选_ **}** +> *SwitchCase 集* → [*SwitchCase*](../chapter3/10_Statements.html#switch_case) [*SwitchCase 集*](../chapter3/10_Statements.html#switch_cases) _可选_ +> *SwitchCase* → [*case 标签*](../chapter3/10_Statements.html#case_label) [*多条语句(Statements)*](../chapter3/10_Statements.html#statements) | [*default 标签*](../chapter3/10_Statements.html#default_label) [*多条语句(Statements)*](../chapter3/10_Statements.html#statements) +> *SwitchCase* → [*case 标签*](../chapter3/10_Statements.html#case_label) **;** | [*default 标签*](../chapter3/10_Statements.html#default_label) **;** +> *case 标签* → **case** [*case 项集*](../chapter3/10_Statements.html#case_item_list) **:** +> *case 项集* → [*模式*](../chapter3/07_Patterns.html#pattern) [*where-clause*](../chapter3/10_Statements.html#guard_clause) _可选_ | [*模式*](../chapter3/07_Patterns.html#pattern) [*where-clause*](../chapter3/10_Statements.html#guard_clause) _可选_ **,** [*case 项集*](../chapter3/10_Statements.html#case_item_list) +> *default 标签* → **default** **:** +> *where 从句* → **where** [*where 表达式*](TODO) +> *where 表达式* → [*表达式*](TODO) -> 控制传递语句(Control Transfer Statement) 语法 +> 标记语句语法 > -> *控制传递语句* → [*break 语句*](../chapter3/10_Statements.html#break_statement) -> *控制传递语句* → [*continue 语句*](../chapter3/10_Statements.html#continue_statement) -> *控制传递语句* → [*fallthrough 语句*](../chapter3/10_Statements.html#fallthrough_statement) -> *控制传递语句* → [*return 语句*](../chapter3/10_Statements.html#return_statement) -> *控制传递语句* → [*throw 语句*](TODO) +> *标记语句(Labeled Statement)* → [*语句标签*](../chapter3/10_Statements.html#statement_label) [*循环语句*](../chapter3/10_Statements.html#loop_statement) | [*语句标签*](../chapter3/10_Statements.html#statement_label) [*if 语句*](../chapter3/10_Statements.html#switch_statement) | [*语句标签*](TODY) [*switch 语句*](TODY) +> *语句标签* → [*标签名称*](../chapter3/10_Statements.html#label_name) **:** +> *标签名称* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) -> Break 语句语法 +> 控制传递语句(Control Transfer Statement) 语法 > -> *break 语句* → **break** [*标签名称*](../chapter3/10_Statements.html#label_name) _可选_ +> *控制传递语句* → [*break 语句*](../chapter3/10_Statements.html#break_statement) +> *控制传递语句* → [*continue 语句*](../chapter3/10_Statements.html#continue_statement) +> *控制传递语句* → [*fallthrough 语句*](../chapter3/10_Statements.html#fallthrough_statement) +> *控制传递语句* → [*return 语句*](../chapter3/10_Statements.html#return_statement) +> *控制传递语句* → [*throw 语句*](TODO) -> Continue 语句语法 +> Break 语句语法 > -> *continue 语句* → **continue** [*标签名称*](../chapter3/10_Statements.html#label_name) _可选_ +> *break 语句* → **break** [*标签名称*](../chapter3/10_Statements.html#label_name) _可选_ -> Fallthrough 语句语法 +> Continue 语句语法 > -> *fallthrough 语句* → **fallthrough** +> *continue 语句* → **continue** [*标签名称*](../chapter3/10_Statements.html#label_name) _可选_ -> Return 语句语法 +> Fallthrough 语句语法 > -> *return 语句* → **return** [*表达式*](../chapter3/04_Expressions.html#expression) _可选_ +> *fallthrough 语句* → **fallthrough** -> 可用条件(Availability Condition)语法 + +> Return 语句语法 > -> *可用条件(availability-condition)* → **#available** **(** [*多可用参数*(availability-arguments)](TODO) **)** -> *多可用参数(availability- arguments)* → [*可用参数(availability-argument)*](TODO)|[*可用参数(availability-argument)*](TODO) , [多可用参数(availability-arguments)](TODO) -> *可用参数(availability- argument)* → [*平台名(platform-name)*](TODO) [*平台版本(platform-version)*](TODO) -> *可用参数(availability- argument)* → * -> -> *平台名* → **iOS** | **iOSApplicationExtension** -> *平台名* → **OSX** | **macOSApplicationExtension** -> *平台名* → **watchOS** -> *平台名* → **tvOS** -> *平台版本* → [*十进制数(decimal-digits)*](TODO) -> *平台版本* → [*十进制数(decimal-digits)*](TODO) . [*十进制数(decimal-digits)*](TODO) -> *平台版本* → [*十进制数(decimal-digits)*](TODO) **.** [*十进制数(decimal-digits)*](TODO) **.** [*十进制数(decimal-digits)*](TODO)) +> *return 语句* → **return** [*表达式*](../chapter3/04_Expressions.html#expression) _可选_ -> 抛出语句(Throw Statement)语法 +> 可用条件(Availability Condition)语法 > -> *抛出语句(throw-statement)* → **throw** [*表达式(expression)*](TODO) +> *可用条件(availability-condition)* → **#available** **(** [*多可用参数*(availability-arguments)](TODO) **)** +> *多可用参数(availability- arguments)* → [*可用参数(availability-argument)*](TODO)|[*可用参数(availability-argument)*](TODO) , [多可用参数(availability-arguments)](TODO) +> *可用参数(availability- argument)* → [*平台名(platform-name)*](TODO) [*平台版本(platform-version)*](TODO) +> *可用参数(availability- argument)* → * +> +> *平台名* → **iOS** | **iOSApplicationExtension** +> *平台名* → **OSX** | **macOSApplicationExtension** +> *平台名* → **watchOS** +> *平台名* → **tvOS** +> *平台版本* → [*十进制数(decimal-digits)*](TODO) +> *平台版本* → [*十进制数(decimal-digits)*](TODO) . [*十进制数(decimal-digits)*](TODO) +> *平台版本* → [*十进制数(decimal-digits)*](TODO) **.** [*十进制数(decimal-digits)*](TODO) **.** [*十进制数(decimal-digits)*](TODO)) -> 延迟语句 (defer-statement)语法 +> 抛出语句(Throw Statement)语法 +> +> *抛出语句(throw-statement)* → **throw** [*表达式(expression)*](TODO) + + +> 延迟语句 (defer-statement)语法 > > *延迟语句(defer-statement)* → **defer** [*代码块*](TODO) -> 执行语句(do-statement)语法 +> 执行语句(do-statement)语法 > -> *执行语句(do-statement)* → **do** [*代码块*](TODO) [*catch-clauses*](TODO) _可选_ -> *catch-clauses* → [*catch-clause*](TODO) [*catch-clauses*](TODO) _可选_ -> *catch-clauses* → **catch** [*模式(pattern)*](TODO) _可选_ [*where-clause*](TODO) _可选_ [*代码块(code-block)*](TODO) _可选_ +> *执行语句(do-statement)* → **do** [*代码块*](TODO) [*catch-clauses*](TODO) _可选_ +> *catch-clauses* → [*catch-clause*](TODO) [*catch-clauses*](TODO) _可选_ +> *catch-clauses* → **catch** [*模式(pattern)*](TODO) _可选_ [*where-clause*](TODO) _可选_ [*代码块(code-block)*](TODO) _可选_ ## 泛型参数 -> 泛型形参从句(Generic Parameter Clause) 语法 +> 泛型形参从句(Generic Parameter Clause) 语法 > -> *泛型参数从句* → **<** [*泛型参数集*](GenericParametersAndArguments.html#generic_parameter_list) [*约束从句*](GenericParametersAndArguments.html#requirement_clause) _可选_ **>** -> *泛型参数集* → [*泛形参数*](GenericParametersAndArguments.html#generic_parameter) | [*泛形参数*](GenericParametersAndArguments.html#generic_parameter) **,** [*泛型参数集*](GenericParametersAndArguments.html#generic_parameter_list) -> *泛形参数* → [*类型名称*](../chapter3/03_Types.html#type_name) -> *泛形参数* → [*类型名称*](../chapter3/03_Types.html#type_name) **:** [*类型标识*](../chapter3/03_Types.html#type_identifier) -> *泛形参数* → [*类型名称*](../chapter3/03_Types.html#type_name) **:** [*协议合成类型*](../chapter3/03_Types.html#protocol_composition_type) -> *约束从句* → **where** [*约束集*](GenericParametersAndArguments.html#requirement_list) -> *约束集* → [*约束*](GenericParametersAndArguments.html#requirement) | [*约束*](GenericParametersAndArguments.html#requirement) **,** [*约束集*](GenericParametersAndArguments.html#requirement_list) -> *约束* → [*一致性约束*](GenericParametersAndArguments.html#conformance_requirement) | [*同类型约束*](GenericParametersAndArguments.html#same_type_requirement) -> *一致性约束* → [*类型标识*](../chapter3/03_Types.html#type_identifier) **:** [*类型标识*](../chapter3/03_Types.html#type_identifier) -> *一致性约束* → [*类型标识*](../chapter3/03_Types.html#type_identifier) **:** [*协议合成类型*](../chapter3/03_Types.html#protocol_composition_type) -> *同类型约束* → [*类型标识*](../chapter3/03_Types.html#type_identifier) **==** [*类型*](../chapter3/03_Types.html#type_identifier) +> *泛型参数从句* → **<** [*泛型参数集*](GenericParametersAndArguments.html#generic_parameter_list) [*约束从句*](GenericParametersAndArguments.html#requirement_clause) _可选_ **>** +> *泛型参数集* → [*泛形参数*](GenericParametersAndArguments.html#generic_parameter) | [*泛形参数*](GenericParametersAndArguments.html#generic_parameter) **,** [*泛型参数集*](GenericParametersAndArguments.html#generic_parameter_list) +> *泛形参数* → [*类型名称*](../chapter3/03_Types.html#type_name) +> *泛形参数* → [*类型名称*](../chapter3/03_Types.html#type_name) **:** [*类型标识*](../chapter3/03_Types.html#type_identifier) +> *泛形参数* → [*类型名称*](../chapter3/03_Types.html#type_name) **:** [*协议合成类型*](../chapter3/03_Types.html#protocol_composition_type) +> *约束从句* → **where** [*约束集*](GenericParametersAndArguments.html#requirement_list) +> *约束集* → [*约束*](GenericParametersAndArguments.html#requirement) | [*约束*](GenericParametersAndArguments.html#requirement) **,** [*约束集*](GenericParametersAndArguments.html#requirement_list) +> *约束* → [*一致性约束*](GenericParametersAndArguments.html#conformance_requirement) | [*同类型约束*](GenericParametersAndArguments.html#same_type_requirement) +> *一致性约束* → [*类型标识*](../chapter3/03_Types.html#type_identifier) **:** [*类型标识*](../chapter3/03_Types.html#type_identifier) +> *一致性约束* → [*类型标识*](../chapter3/03_Types.html#type_identifier) **:** [*协议合成类型*](../chapter3/03_Types.html#protocol_composition_type) +> *同类型约束* → [*类型标识*](../chapter3/03_Types.html#type_identifier) **==** [*类型*](../chapter3/03_Types.html#type_identifier) -> 泛型实参从句语法 +> 泛型实参从句语法 > -> *(泛型参数从句 Generic Argument Clause)* → **<** [*泛型参数集*](GenericParametersAndArguments.html#generic_argument_list) **>** -> *泛型参数集* → [*泛型参数*](GenericParametersAndArguments.html#generic_argument) | [*泛型参数*](GenericParametersAndArguments.html#generic_argument) **,** [*泛型参数集*](GenericParametersAndArguments.html#generic_argument_list) -> *泛型参数* → [*类型*](../chapter3/03_Types.html#type) +> *(泛型参数从句 Generic Argument Clause)* → **<** [*泛型参数集*](GenericParametersAndArguments.html#generic_argument_list) **>** +> *泛型参数集* → [*泛型参数*](GenericParametersAndArguments.html#generic_argument) | [*泛型参数*](GenericParametersAndArguments.html#generic_argument) **,** [*泛型参数集*](GenericParametersAndArguments.html#generic_argument_list) +> *泛型参数* → [*类型*](../chapter3/03_Types.html#type) -## 声明 (Declarations) +## 声明 (Declarations) -> 声明语法 +> 声明语法 > -> *声明* → [*导入声明*](../chapter3/05_Declarations.html#import_declaration) -> *声明* → [*常量声明*](../chapter3/05_Declarations.html#constant_declaration) -> *声明* → [*变量声明*](../chapter3/05_Declarations.html#variable_declaration) -> *声明* → [*类型别名声明*](../chapter3/05_Declarations.html#typealias_declaration) -> *声明* → [*函数声明*](../chapter3/05_Declarations.html#function_declaration) -> *声明* → [*枚举声明*](../chapter3/05_Declarations.html#enum_declaration) -> *声明* → [*结构体声明*](../chapter3/05_Declarations.html#struct_declaration) -> *声明* → [*类声明*](../chapter3/05_Declarations.html#class_declaration) -> *声明* → [*协议声明*](../chapter3/05_Declarations.html#protocol_declaration) -> *声明* → [*构造器声明*](../chapter3/05_Declarations.html#initializer_declaration) -> *声明* → [*析构器声明*](../chapter3/05_Declarations.html#deinitializer_declaration) -> *声明* → [*扩展声明*](../chapter3/05_Declarations.html#extension_declaration) -> *声明* → [*下标声明*](../chapter3/05_Declarations.html#subscript_declaration) -> *声明* → [*运算符声明*](../chapter3/05_Declarations.html#operator_declaration) -> *声明(Declarations)集* → [*声明*](../chapter3/05_Declarations.html#declaration) [*声明(Declarations)集*](../chapter3/05_Declarations.html#declarations) _可选_ - +> *声明* → [*导入声明*](../chapter3/05_Declarations.html#import_declaration) +> *声明* → [*常量声明*](../chapter3/05_Declarations.html#constant_declaration) +> *声明* → [*变量声明*](../chapter3/05_Declarations.html#variable_declaration) +> *声明* → [*类型别名声明*](../chapter3/05_Declarations.html#typealias_declaration) +> *声明* → [*函数声明*](../chapter3/05_Declarations.html#function_declaration) +> *声明* → [*枚举声明*](../chapter3/05_Declarations.html#enum_declaration) +> *声明* → [*结构体声明*](../chapter3/05_Declarations.html#struct_declaration) +> *声明* → [*类声明*](../chapter3/05_Declarations.html#class_declaration) +> *声明* → [*协议声明*](../chapter3/05_Declarations.html#protocol_declaration) +> *声明* → [*构造器声明*](../chapter3/05_Declarations.html#initializer_declaration) +> *声明* → [*析构器声明*](../chapter3/05_Declarations.html#deinitializer_declaration) +> *声明* → [*扩展声明*](../chapter3/05_Declarations.html#extension_declaration) +> *声明* → [*下标声明*](../chapter3/05_Declarations.html#subscript_declaration) +> *声明* → [*运算符声明*](../chapter3/05_Declarations.html#operator_declaration) +> *声明(Declarations)集* → [*声明*](../chapter3/05_Declarations.html#declaration) [*声明(Declarations)集*](../chapter3/05_Declarations.html#declarations) _可选_ + -> 顶级(Top Level) 声明语法 +> 顶级(Top Level) 声明语法 > -> *顶级声明* → [*多条语句(Statements)*](../chapter3/10_Statements.html#statements) _可选_ +> *顶级声明* → [*多条语句(Statements)*](../chapter3/10_Statements.html#statements) _可选_ -> 代码块语法 +> 代码块语法 > -> *代码块* → **{** [*多条语句(Statements)*](../chapter3/10_Statements.html#statements) _可选_ **}** +> *代码块* → **{** [*多条语句(Statements)*](../chapter3/10_Statements.html#statements) _可选_ **}** -> 导入(Import)声明语法 +> 导入(Import)声明语法 > -> *导入声明* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ **import** [*导入类型*](../chapter3/05_Declarations.html#import_kind) _可选_ [*导入路径*](../chapter3/05_Declarations.html#import_path) -> *导入类型* → **typealias** | **struct** | **class** | **enum** | **protocol** | **var** | **func** -> *导入路径* → [*导入路径标识符*](../chapter3/05_Declarations.html#import_path_identifier) | [*导入路径标识符*](../chapter3/05_Declarations.html#import_path_identifier) **.** [*导入路径*](../chapter3/05_Declarations.html#import_path) -> *导入路径标识符* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) | [*运算符*](../chapter3/02_Lexical_Structure.html#operator) +> *导入声明* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ **import** [*导入类型*](../chapter3/05_Declarations.html#import_kind) _可选_ [*导入路径*](../chapter3/05_Declarations.html#import_path) +> *导入类型* → **typealias** | **struct** | **class** | **enum** | **protocol** | **var** | **func** +> *导入路径* → [*导入路径标识符*](../chapter3/05_Declarations.html#import_path_identifier) | [*导入路径标识符*](../chapter3/05_Declarations.html#import_path_identifier) **.** [*导入路径*](../chapter3/05_Declarations.html#import_path) +> *导入路径标识符* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) | [*运算符*](../chapter3/02_Lexical_Structure.html#operator) -> 常数声明语法 +> 常数声明语法 > -> *常量声明* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*声明修改符(Modifiers)集*](../chapter3/05_Declarations.html#declaration_specifiers) _可选_ **let** [*模式构造器集*](../chapter3/05_Declarations.html#pattern_initializer_list) -> *模式构造器集* → [*模式构造器*](../chapter3/05_Declarations.html#pattern_initializer) | [*模式构造器*](../chapter3/05_Declarations.html#pattern_initializer) **,** [*模式构造器集*](../chapter3/05_Declarations.html#pattern_initializer_list) -> *模式构造器* → [*模式*](../ chapter3/07_Patterns.html#pattern) [*构造器*](../chapter3/05_Declarations.html#initializer) _可选_ -> *构造器* → **=** [*表达式*](../chapter3/04_Expressions.html#expression) +> *常量声明* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*声明修改符(Modifiers)集*](../chapter3/05_Declarations.html#declaration_specifiers) _可选_ **let** [*模式构造器集*](../chapter3/05_Declarations.html#pattern_initializer_list) +> *模式构造器集* → [*模式构造器*](../chapter3/05_Declarations.html#pattern_initializer) | [*模式构造器*](../chapter3/05_Declarations.html#pattern_initializer) **,** [*模式构造器集*](../chapter3/05_Declarations.html#pattern_initializer_list) +> *模式构造器* → [*模式*](../ chapter3/07_Patterns.html#pattern) [*构造器*](../chapter3/05_Declarations.html#initializer) _可选_ +> *构造器* → **=** [*表达式*](../chapter3/04_Expressions.html#expression) -> 变量声明语法 +> 变量声明语法 > -> *变量声明* → [*变量声明头(Head)*](../chapter3/05_Declarations.html#variable_declaration_head) [*模式构造器集*](../chapter3/05_Declarations.html#pattern_initializer_list) -> *变量声明* → [*变量声明头(Head)*](../chapter3/05_Declarations.html#variable_declaration_head) [*变量名*](../chapter3/05_Declarations.html#variable_name) [*类型注解*](../chapter3/03_Types.html#type_annotation) [*代码块*](../chapter3/05_Declarations.html#code_block) -> *变量声明* → [*变量声明头(Head)*](../chapter3/05_Declarations.html#variable_declaration_head) [*变量名*](../chapter3/05_Declarations.html#variable_name) [*类型注解*](../chapter3/03_Types.html#type_annotation) [*getter-setter 块*](../chapter3/05_Declarations.html#getter_setter_block) -> *变量声明* → [*变量声明头(Head)*](../chapter3/05_Declarations.html#variable_declaration_head) [*变量名*](../chapter3/05_Declarations.html#variable_name) [*类型注解*](../chapter3/03_Types.html#type_annotation) [*getter-setter 关键字(Keyword)块*](../chapter3/05_Declarations.html#getter_setter_keyword_block) -> *变量声明* → [*变量声明头(Head)*](../chapter3/05_Declarations.html#variable_declaration_head) [*变量名*](../chapter3/05_Declarations.html#variable_name) [*类型注解*](../chapter3/03_Types.html#type_annotation) [*构造器*](../chapter3/05_Declarations.html#initializer) _可选_ [*willSet-didSet 代码块*](../chapter3/05_Declarations.html#willSet_didSet_block) -> *变量声明头(Head)* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*声明修改符(Modifers)集*](../chapter3/05_Declarations.html#declaration_specifiers) _可选_ **var** +> *变量声明* → [*变量声明头(Head)*](../chapter3/05_Declarations.html#variable_declaration_head) [*模式构造器集*](../chapter3/05_Declarations.html#pattern_initializer_list) +> *变量声明* → [*变量声明头(Head)*](../chapter3/05_Declarations.html#variable_declaration_head) [*变量名*](../chapter3/05_Declarations.html#variable_name) [*类型注解*](../chapter3/03_Types.html#type_annotation) [*代码块*](../chapter3/05_Declarations.html#code_block) +> *变量声明* → [*变量声明头(Head)*](../chapter3/05_Declarations.html#variable_declaration_head) [*变量名*](../chapter3/05_Declarations.html#variable_name) [*类型注解*](../chapter3/03_Types.html#type_annotation) [*getter-setter 块*](../chapter3/05_Declarations.html#getter_setter_block) +> *变量声明* → [*变量声明头(Head)*](../chapter3/05_Declarations.html#variable_declaration_head) [*变量名*](../chapter3/05_Declarations.html#variable_name) [*类型注解*](../chapter3/03_Types.html#type_annotation) [*getter-setter 关键字(Keyword)块*](../chapter3/05_Declarations.html#getter_setter_keyword_block) +> *变量声明* → [*变量声明头(Head)*](../chapter3/05_Declarations.html#variable_declaration_head) [*变量名*](../chapter3/05_Declarations.html#variable_name) [*类型注解*](../chapter3/03_Types.html#type_annotation) [*构造器*](../chapter3/05_Declarations.html#initializer) _可选_ [*willSet-didSet 代码块*](../chapter3/05_Declarations.html#willSet_didSet_block) +> *变量声明头(Head)* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*声明修改符(Modifers)集*](../chapter3/05_Declarations.html#declaration_specifiers) _可选_ **var** > *变量名称* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) -> *getter-setter 块* → **{** [*getter 从句*](../chapter3/05_Declarations.html#getter_clause) [*setter 从句*](../chapter3/05_Declarations.html#setter_clause) _可选_ **}** -> *getter-setter 块* → **{** [*setter 从句*](../chapter3/05_Declarations.html#setter_clause) [*getter 从句*](../chapter3/05_Declarations.html#getter_clause) **}** -> *getter 从句* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ **get** [*代码块*](../chapter3/05_Declarations.html#code_block) -> *setter 从句* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ **set** [*setter 名称*](../chapter3/05_Declarations.html#setter_name) _可选_ [*代码块*](../chapter3/05_Declarations.html#code_block) -> *setter 名称* → **(** [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) **)** -> *getter-setter 关键字(Keyword)块* → **{** [*getter 关键字(Keyword)从句*](../chapter3/05_Declarations.html#getter_keyword_clause) [*setter 关键字(Keyword)从句*](../chapter3/05_Declarations.html#setter_keyword_clause) _可选_ **}** -> *getter-setter 关键字(Keyword)块* → **{** [*setter 关键字(Keyword)从句*](../chapter3/05_Declarations.html#setter_keyword_clause) [*getter 关键字(Keyword)从句*](../chapter3/05_Declarations.html#getter_keyword_clause) **}** +> *getter-setter 块* → **{** [*getter 从句*](../chapter3/05_Declarations.html#getter_clause) [*setter 从句*](../chapter3/05_Declarations.html#setter_clause) _可选_ **}** +> *getter-setter 块* → **{** [*setter 从句*](../chapter3/05_Declarations.html#setter_clause) [*getter 从句*](../chapter3/05_Declarations.html#getter_clause) **}** +> *getter 从句* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ **get** [*代码块*](../chapter3/05_Declarations.html#code_block) +> *setter 从句* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ **set** [*setter 名称*](../chapter3/05_Declarations.html#setter_name) _可选_ [*代码块*](../chapter3/05_Declarations.html#code_block) +> *setter 名称* → **(** [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) **)** +> *getter-setter 关键字(Keyword)块* → **{** [*getter 关键字(Keyword)从句*](../chapter3/05_Declarations.html#getter_keyword_clause) [*setter 关键字(Keyword)从句*](../chapter3/05_Declarations.html#setter_keyword_clause) _可选_ **}** +> *getter-setter 关键字(Keyword)块* → **{** [*setter 关键字(Keyword)从句*](../chapter3/05_Declarations.html#setter_keyword_clause) [*getter 关键字(Keyword)从句*](../chapter3/05_Declarations.html#getter_keyword_clause) **}** > *getter 关键字(Keyword)从句* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ **get** -> *setter 关键字(Keyword)从句* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ **set** -> *willSet-didSet 代码块* → **{** [*willSet 从句*](../chapter3/05_Declarations.html#willSet_clause) [*didSet 从句*](../chapter3/05_Declarations.html#didSet_clause) _可选_ **}** -> *willSet-didSet 代码块* → **{** [*didSet 从句*](../chapter3/05_Declarations.html#didSet_clause) [*willSet 从句*](../chapter3/05_Declarations.html#willSet_clause) **}** -> *willSet 从句* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ **willSet** [*setter 名称*](../chapter3/05_Declarations.html#setter_name) _可选_ [*代码块*](../chapter3/05_Declarations.html#code_block) -> *didSet 从句* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ - **didSet** [*setter 名称*](../chapter3/05_Declarations.html#setter_name) _可选_ [*代码块*](../chapter3/05_Declarations.html#code_block) +> *setter 关键字(Keyword)从句* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ **set** +> *willSet-didSet 代码块* → **{** [*willSet 从句*](../chapter3/05_Declarations.html#willSet_clause) [*didSet 从句*](../chapter3/05_Declarations.html#didSet_clause) _可选_ **}** +> *willSet-didSet 代码块* → **{** [*didSet 从句*](../chapter3/05_Declarations.html#didSet_clause) [*willSet 从句*](../chapter3/05_Declarations.html#willSet_clause) **}** +> *willSet 从句* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ **willSet** [*setter 名称*](../chapter3/05_Declarations.html#setter_name) _可选_ [*代码块*](../chapter3/05_Declarations.html#code_block) +> *didSet 从句* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ + **didSet** [*setter 名称*](../chapter3/05_Declarations.html#setter_name) _可选_ [*代码块*](../chapter3/05_Declarations.html#code_block) -> 类型别名声明语法 +> 类型别名声明语法 > -> *类型别名声明* → [*类型别名头(Head)*](../chapter3/05_Declarations.html#typealias_head) [*类型别名赋值*](../chapter3/05_Declarations.html#typealias_assignment) -> *类型别名头(Head)* → [*属性*](TODO) _可选_ [*访问级别修改符(access-level-modifier)*](TODO) **typealias** [*类型别名名称*](../chapter3/05_Declarations.html#typealias_name) -> *类型别名名称* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) -> *类型别名赋值* → **=** [*类型*](../chapter3/03_Types.html#type) +> *类型别名声明* → [*类型别名头(Head)*](../chapter3/05_Declarations.html#typealias_head) [*类型别名赋值*](../chapter3/05_Declarations.html#typealias_assignment) +> *类型别名头(Head)* → [*属性*](TODO) _可选_ [*访问级别修改符(access-level-modifier)*](TODO) **typealias** [*类型别名名称*](../chapter3/05_Declarations.html#typealias_name) +> *类型别名名称* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) +> *类型别名赋值* → **=** [*类型*](../chapter3/03_Types.html#type) -> 函数声明语法 +> 函数声明语法 > -> *函数声明* → [*函数头*](../chapter3/05_Declarations.html#function_head) [*函数名*](../chapter3/05_Declarations.html#function_name) [*泛型参数从句*](GenericParametersAndArguments.html#generic_parameter_clause) _可选_ [*函数签名(Signature)*](../chapter3/05_Declarations.html#function_signature) [*函数体*](../chapter3/05_Declarations.html#function_body) -> *函数头* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*声明描述符(Specifiers)集*](../chapter3/05_Declarations.html#declaration_specifiers) _可选_ **func** -> *函数名* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) | [*运算符*](../chapter3/02_Lexical_Structure.html#operator) -> *函数签名(Signature)* → [*parameter-clauses*](../chapter3/05_Declarations.html#parameter_clauses) **throws** _可选_ [*函数结果*](../chapter3/05_Declarations.html#function_result) _可选_ +> *函数声明* → [*函数头*](../chapter3/05_Declarations.html#function_head) [*函数名*](../chapter3/05_Declarations.html#function_name) [*泛型参数从句*](GenericParametersAndArguments.html#generic_parameter_clause) _可选_ [*函数签名(Signature)*](../chapter3/05_Declarations.html#function_signature) [*函数体*](../chapter3/05_Declarations.html#function_body) +> *函数头* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*声明描述符(Specifiers)集*](../chapter3/05_Declarations.html#declaration_specifiers) _可选_ **func** +> *函数名* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) | [*运算符*](../chapter3/02_Lexical_Structure.html#operator) +> *函数签名(Signature)* → [*parameter-clauses*](../chapter3/05_Declarations.html#parameter_clauses) **throws** _可选_ [*函数结果*](../chapter3/05_Declarations.html#function_result) _可选_ -> *函数签名(Signature)* → [*parameter-clauses*](../chapter3/05_Declarations.html#parameter_clauses) **rethrows** [*函数结果*](../chapter3/05_Declarations.html#function_result) _可选_ -> *函数结果* → **->** [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*类型*](../chapter3/03_Types.html#type) -> *函数体* → [*代码块*](../chapter3/05_Declarations.html#code_block) -> *参数从句* → [*参数从句*](../chapter3/05_Declarations.html#parameter_clause) [*parameter-clauses*](../chapter3/05_Declarations.html#parameter_clauses) _可选_ -> *参数从句* → **(** **)** | **(** [*参数集*](../chapter3/05_Declarations.html#parameter_list) **...** _可选_ **)** -> *参数集* → [*参数*](../chapter3/05_Declarations.html#parameter) | [*参数*](../chapter3/05_Declarations.html#parameter) **,** [*参数集*](../chapter3/05_Declarations.html#parameter_list) -> *参数* → **inout** _可选_ **let** _可选_ [*外部参数名*](../chapter3/05_Declarations.html#parameter_name) _可选_ [*本地参数名*](../chapter3/05_Declarations.html#local_parameter_name) _可选_ [*类型注解*](../chapter3/03_Types.html#type_annotation) [*默认参数从句*](../chapter3/05_Declarations.html#default_argument_clause) _可选_ -> *参数* → **inout** _可选_ **var** [*外部参数名*](../chapter3/05_Declarations.html#parameter_name) [*本地参数名*](../chapter3/05_Declarations.html#local_parameter_name) _可选_ [*类型注解*](../chapter3/03_Types.html#type_annotation) [*默认参数从句*](../chapter3/05_Declarations.html#default_argument_clause) _可选_ -> *参数* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*类型*](../chapter3/03_Types.html#type) -> *外部参数名* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) | **_** -> *本地参数名* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) | **_** -> *默认参数从句* → **=** [*表达式*](../chapter3/04_Expressions.html#expression) +> *函数签名(Signature)* → [*parameter-clauses*](../chapter3/05_Declarations.html#parameter_clauses) **rethrows** [*函数结果*](../chapter3/05_Declarations.html#function_result) _可选_ +> *函数结果* → **->** [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*类型*](../chapter3/03_Types.html#type) +> *函数体* → [*代码块*](../chapter3/05_Declarations.html#code_block) +> *参数从句* → [*参数从句*](../chapter3/05_Declarations.html#parameter_clause) [*parameter-clauses*](../chapter3/05_Declarations.html#parameter_clauses) _可选_ +> *参数从句* → **(** **)** | **(** [*参数集*](../chapter3/05_Declarations.html#parameter_list) **...** _可选_ **)** +> *参数集* → [*参数*](../chapter3/05_Declarations.html#parameter) | [*参数*](../chapter3/05_Declarations.html#parameter) **,** [*参数集*](../chapter3/05_Declarations.html#parameter_list) +> *参数* → **inout** _可选_ **let** _可选_ [*外部参数名*](../chapter3/05_Declarations.html#parameter_name) _可选_ [*本地参数名*](../chapter3/05_Declarations.html#local_parameter_name) _可选_ [*类型注解*](../chapter3/03_Types.html#type_annotation) [*默认参数从句*](../chapter3/05_Declarations.html#default_argument_clause) _可选_ +> *参数* → **inout** _可选_ **var** [*外部参数名*](../chapter3/05_Declarations.html#parameter_name) [*本地参数名*](../chapter3/05_Declarations.html#local_parameter_name) _可选_ [*类型注解*](../chapter3/03_Types.html#type_annotation) [*默认参数从句*](../chapter3/05_Declarations.html#default_argument_clause) _可选_ +> *参数* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*类型*](../chapter3/03_Types.html#type) +> *外部参数名* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) | **_** +> *本地参数名* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) | **_** +> *默认参数从句* → **=** [*表达式*](../chapter3/04_Expressions.html#expression) -> 枚举声明语法 +> 枚举声明语法 > -> *枚举声明* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*访问级别修改器(access-level-modifier)*](TODO) _可选_ [*联合式枚举*](../chapter3/05_Declarations.html#union_style_enum) -> *枚举声明* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*访问级别修改器(access-level-modifier)*](TODO) _可选_ [*原始值式枚举(raw-value-style-enum)*](TODO) -> *联合式枚举* → **enum** [*枚举名*](../chapter3/05_Declarations.html#enum_name) [*泛型参数从句*](GenericParametersAndArguments.html#generic_parameter_clause) _可选_ [*类型继承从句(type-inheritance-clause)*](TODO) _可选_ **{** [*联合样式枚举成员*](../chapter3/05_Declarations.html#union_style_enum_members) _可选_ **}** -> *联合样式枚举成员* → [*union-style-enum-member*](../chapter3/05_Declarations.html#union_style_enum_member) [*联合样式枚举成员*](../chapter3/05_Declarations.html#union_style_enum_members) _可选_ -> *联合样式枚举成员* → [*声明*](../chapter3/05_Declarations.html#declaration) | [*联合式(Union Style)的枚举 case 从句*](../chapter3/05_Declarations.html#union_style_enum_case_clause) -> *联合式(Union Style)的枚举 case 从句* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ **case** [*联合式(Union Style)的枚举 case 集*](../chapter3/05_Declarations.html#union_style_enum_case_list) -> *联合式(Union Style)的枚举 case 集* → [*联合式(Union Style)的 case*](../chapter3/05_Declarations.html#union_style_enum_case) | [*联合式(Union Style)的 case*](../chapter3/05_Declarations.html#union_style_enum_case) **,** [*联合式(Union Style)的枚举 case 集*](../chapter3/05_Declarations.html#union_style_enum_case_list) -> *联合式(Union Style)的枚举 case* → [*枚举的 case 名*](../chapter3/05_Declarations.html#enum_case_name) [*元组类型*](../chapter3/03_Types.html#tuple_type) _可选_ -> *枚举名* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) -> *枚举的 case 名* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) -> *原始值式枚举* → **enum** [*枚举名*](../chapter3/05_Declarations.html#enum_name) [*泛型参数从句*](GenericParametersAndArguments.html#generic_parameter_clause) _可选_ **:** [*类型标识*](../chapter3/03_Types.html#type_identifier) **{** [*原始值式枚举成员集*](../chapter3/05_Declarations.html#raw_value_style_enum_members) _可选_ **}** -> *原始值式枚举成员集* → [*原始值式枚举成员*](../chapter3/05_Declarations.html#raw_value_style_enum_member) [*原始值式枚举成员集*](../chapter3/05_Declarations.html#raw_value_style_enum_members) _可选_ -> *原始值式枚举成员* → [*声明*](../chapter3/05_Declarations.html#declaration) | [*原始值式枚举 case 从句*](../chapter3/05_Declarations.html#raw_value_style_enum_case_clause) -> *原始值式枚举 case 从句* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ **case** [*原始值式枚举 case 集*](../chapter3/05_Declarations.html#raw_value_style_enum_case_list) -> *原始值式枚举 case 集* → [*原始值式枚举 case*](../chapter3/05_Declarations.html#raw_value_style_enum_case) | [*原始值式枚举 case*](../chapter3/05_Declarations.html#raw_value_style_enum_case) **,** [*原始值式枚举 case 集*](../chapter3/05_Declarations.html#raw_value_style_enum_case_list) -> *原始值式枚举 case* → [*枚举的 case 名*](../chapter3/05_Declarations.html#enum_case_name) [*原始值赋值*](../chapter3/05_Declarations.html#raw_value_assignment) _可选_ -> *原始值赋值* → **=** [*字面量*](../chapter3/02_Lexical_Structure.html#literal) -> *原始值字面量(raw-value-literal)* → [*数值字面量*](TODO) | [*字符串字面量*](TODO) | [*布尔字面量*](TODO) +> *枚举声明* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*访问级别修改器(access-level-modifier)*](TODO) _可选_ [*联合式枚举*](../chapter3/05_Declarations.html#union_style_enum) +> *枚举声明* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*访问级别修改器(access-level-modifier)*](TODO) _可选_ [*原始值式枚举(raw-value-style-enum)*](TODO) +> *联合式枚举* → **enum** [*枚举名*](../chapter3/05_Declarations.html#enum_name) [*泛型参数从句*](GenericParametersAndArguments.html#generic_parameter_clause) _可选_ [*类型继承从句(type-inheritance-clause)*](TODO) _可选_ **{** [*联合样式枚举成员*](../chapter3/05_Declarations.html#union_style_enum_members) _可选_ **}** +> *联合样式枚举成员* → [*union-style-enum-member*](../chapter3/05_Declarations.html#union_style_enum_member) [*联合样式枚举成员*](../chapter3/05_Declarations.html#union_style_enum_members) _可选_ +> *联合样式枚举成员* → [*声明*](../chapter3/05_Declarations.html#declaration) | [*联合式(Union Style)的枚举 case 从句*](../chapter3/05_Declarations.html#union_style_enum_case_clause) +> *联合式(Union Style)的枚举 case 从句* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ **case** [*联合式(Union Style)的枚举 case 集*](../chapter3/05_Declarations.html#union_style_enum_case_list) +> *联合式(Union Style)的枚举 case 集* → [*联合式(Union Style)的 case*](../chapter3/05_Declarations.html#union_style_enum_case) | [*联合式(Union Style)的 case*](../chapter3/05_Declarations.html#union_style_enum_case) **,** [*联合式(Union Style)的枚举 case 集*](../chapter3/05_Declarations.html#union_style_enum_case_list) +> *联合式(Union Style)的枚举 case* → [*枚举的 case 名*](../chapter3/05_Declarations.html#enum_case_name) [*元组类型*](../chapter3/03_Types.html#tuple_type) _可选_ +> *枚举名* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) +> *枚举的 case 名* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) +> *原始值式枚举* → **enum** [*枚举名*](../chapter3/05_Declarations.html#enum_name) [*泛型参数从句*](GenericParametersAndArguments.html#generic_parameter_clause) _可选_ **:** [*类型标识*](../chapter3/03_Types.html#type_identifier) **{** [*原始值式枚举成员集*](../chapter3/05_Declarations.html#raw_value_style_enum_members) _可选_ **}** +> *原始值式枚举成员集* → [*原始值式枚举成员*](../chapter3/05_Declarations.html#raw_value_style_enum_member) [*原始值式枚举成员集*](../chapter3/05_Declarations.html#raw_value_style_enum_members) _可选_ +> *原始值式枚举成员* → [*声明*](../chapter3/05_Declarations.html#declaration) | [*原始值式枚举 case 从句*](../chapter3/05_Declarations.html#raw_value_style_enum_case_clause) +> *原始值式枚举 case 从句* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ **case** [*原始值式枚举 case 集*](../chapter3/05_Declarations.html#raw_value_style_enum_case_list) +> *原始值式枚举 case 集* → [*原始值式枚举 case*](../chapter3/05_Declarations.html#raw_value_style_enum_case) | [*原始值式枚举 case*](../chapter3/05_Declarations.html#raw_value_style_enum_case) **,** [*原始值式枚举 case 集*](../chapter3/05_Declarations.html#raw_value_style_enum_case_list) +> *原始值式枚举 case* → [*枚举的 case 名*](../chapter3/05_Declarations.html#enum_case_name) [*原始值赋值*](../chapter3/05_Declarations.html#raw_value_assignment) _可选_ +> *原始值赋值* → **=** [*字面量*](../chapter3/02_Lexical_Structure.html#literal) +> *原始值字面量(raw-value-literal)* → [*数值字面量*](TODO) | [*字符串字面量*](TODO) | [*布尔字面量*](TODO) -> 结构体声明语法 +> 结构体声明语法 > -> *结构体声明* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*访问级别修改器(access-level-modifier)*](TODO) _可选_ **struct** [*结构体名称*](../chapter3/05_Declarations.html#struct_name) [*泛型参数从句*](GenericParametersAndArguments.html#generic_parameter_clause) _可选_ [*类型继承从句*](../chapter3/03_Types.html#type_inheritance_clause) _可选_ [*结构体主体*](../chapter3/05_Declarations.html#struct_body) -> *结构体名称* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) -> *结构体主体* → **{** [*声明(Declarations)集*](../chapter3/05_Declarations.html#declarations) _可选_ **}** +> *结构体声明* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*访问级别修改器(access-level-modifier)*](TODO) _可选_ **struct** [*结构体名称*](../chapter3/05_Declarations.html#struct_name) [*泛型参数从句*](GenericParametersAndArguments.html#generic_parameter_clause) _可选_ [*类型继承从句*](../chapter3/03_Types.html#type_inheritance_clause) _可选_ [*结构体主体*](../chapter3/05_Declarations.html#struct_body) +> *结构体名称* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) +> *结构体主体* → **{** [*声明(Declarations)集*](../chapter3/05_Declarations.html#declarations) _可选_ **}** -> 类声明语法 +> 类声明语法 > -> *类声明* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*访问级别修改器(access-level-modifier)*](TODO) **class** [*类名*](../chapter3/05_Declarations.html#class_name) [*泛型参数从句*](GenericParametersAndArguments.html#generic_parameter_clause) _可选_ [*类型继承从句*](../chapter3/03_Types.html#type_inheritance_clause) _可选_ [*类主体*](../chapter3/05_Declarations.html#class_body) -> *类名* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) -> *类主体* → **{** [*声明(Declarations)集*](../chapter3/05_Declarations.html#declarations) _可选_ **}** +> *类声明* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*访问级别修改器(access-level-modifier)*](TODO) **class** [*类名*](../chapter3/05_Declarations.html#class_name) [*泛型参数从句*](GenericParametersAndArguments.html#generic_parameter_clause) _可选_ [*类型继承从句*](../chapter3/03_Types.html#type_inheritance_clause) _可选_ [*类主体*](../chapter3/05_Declarations.html#class_body) +> *类名* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) +> *类主体* → **{** [*声明(Declarations)集*](../chapter3/05_Declarations.html#declarations) _可选_ **}** -> 协议(Protocol)声明语法 +> 协议(Protocol)声明语法 > -> *协议声明* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_[*访问级别修改器(access-level-modifier)*](TODO) **protocol** [*协议名*](../chapter3/05_Declarations.html#protocol_name) [*类型继承从句*](../chapter3/03_Types.html#type_inheritance_clause) _可选_ [*协议主体*](../chapter3/05_Declarations.html#protocol_body) -> *协议名* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) -> *协议主体* → **{** [*协议成员声明(Declarations)集*](../chapter3/05_Declarations.html#protocol_member_declarations) _可选_ **}** -> *协议成员声明* → [*协议属性声明*](../chapter3/05_Declarations.html#protocol_property_declaration) -> *协议成员声明* → [*协议方法声明*](../chapter3/05_Declarations.html#protocol_method_declaration) -> *协议成员声明* → [*协议构造器声明*](../chapter3/05_Declarations.html#protocol_initializer_declaration) -> *协议成员声明* → [*协议下标声明*](../chapter3/05_Declarations.html#protocol_subscript_declaration) -> *协议成员声明* → [*协议关联类型声明*](../chapter3/05_Declarations.html#protocol_associated_type_declaration) -> *协议成员声明(Declarations)集* → [*协议成员声明*](../chapter3/05_Declarations.html#protocol_member_declaration) [*协议成员声明(Declarations)集*](../chapter3/05_Declarations.html#protocol_member_declarations) _可选_ +> *协议声明* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_[*访问级别修改器(access-level-modifier)*](TODO) **protocol** [*协议名*](../chapter3/05_Declarations.html#protocol_name) [*类型继承从句*](../chapter3/03_Types.html#type_inheritance_clause) _可选_ [*协议主体*](../chapter3/05_Declarations.html#protocol_body) +> *协议名* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) +> *协议主体* → **{** [*协议成员声明(Declarations)集*](../chapter3/05_Declarations.html#protocol_member_declarations) _可选_ **}** +> *协议成员声明* → [*协议属性声明*](../chapter3/05_Declarations.html#protocol_property_declaration) +> *协议成员声明* → [*协议方法声明*](../chapter3/05_Declarations.html#protocol_method_declaration) +> *协议成员声明* → [*协议构造器声明*](../chapter3/05_Declarations.html#protocol_initializer_declaration) +> *协议成员声明* → [*协议下标声明*](../chapter3/05_Declarations.html#protocol_subscript_declaration) +> *协议成员声明* → [*协议关联类型声明*](../chapter3/05_Declarations.html#protocol_associated_type_declaration) +> *协议成员声明(Declarations)集* → [*协议成员声明*](../chapter3/05_Declarations.html#protocol_member_declaration) [*协议成员声明(Declarations)集*](../chapter3/05_Declarations.html#protocol_member_declarations) _可选_ -> 协议属性声明语法 +> 协议属性声明语法 > -> *协议属性声明* → [*变量声明头(Head)*](../chapter3/05_Declarations.html#variable_declaration_head) [*变量名*](../chapter3/05_Declarations.html#variable_name) [*类型注解*](../chapter3/03_Types.html#type_annotation) [*getter-setter 关键字(Keyword)块*](../chapter3/05_Declarations.html#getter_setter_keyword_block) +> *协议属性声明* → [*变量声明头(Head)*](../chapter3/05_Declarations.html#variable_declaration_head) [*变量名*](../chapter3/05_Declarations.html#variable_name) [*类型注解*](../chapter3/03_Types.html#type_annotation) [*getter-setter 关键字(Keyword)块*](../chapter3/05_Declarations.html#getter_setter_keyword_block) -> 协议方法声明语法 +> 协议方法声明语法 > -> *协议方法声明* → [*函数头*](../chapter3/05_Declarations.html#function_head) [*函数名*](../chapter3/05_Declarations.html#function_name) [*泛型参数从句*](GenericParametersAndArguments.html#generic_parameter_clause) _可选_ [*函数签名(Signature)*](../chapter3/05_Declarations.html#function_signature) +> *协议方法声明* → [*函数头*](../chapter3/05_Declarations.html#function_head) [*函数名*](../chapter3/05_Declarations.html#function_name) [*泛型参数从句*](GenericParametersAndArguments.html#generic_parameter_clause) _可选_ [*函数签名(Signature)*](../chapter3/05_Declarations.html#function_signature) -> 协议构造器声明语法 +> 协议构造器声明语法 > > *协议构造器声明* → [*构造器头(Head)*](../chapter3/05_Declarations.html#initializer_head) [*泛型参数从句*](GenericParametersAndArguments.html#generic_parameter_clause) _可选_ [*参数从句*](../chapter3/05_Declarations.html#parameter_clause) -> 协议下标声明语法 +> 协议下标声明语法 > > *协议下标声明* → [*下标头(Head)*](../chapter3/05_Declarations.html#subscript_head) [*下标结果(Result)*](../chapter3/05_Declarations.html#subscript_result) [*getter-setter 关键字(Keyword)块*](../chapter3/05_Declarations.html#getter_setter_keyword_block) -> 协议关联类型声明语法 +> 协议关联类型声明语法 > > *协议关联类型声明* → [*类型别名头(Head)*](../chapter3/05_Declarations.html#typealias_head) [*类型继承从句*](../chapter3/03_Types.html#type_inheritance_clause) _可选_ [*类型别名赋值*](../chapter3/05_Declarations.html#typealias_assignment) _可选_ -> 构造器声明语法 +> 构造器声明语法 > -> *构造器声明* → [*构造器头(Head)*](../chapter3/05_Declarations.html#initializer_head) [*泛型参数从句*](GenericParametersAndArguments.html#generic_parameter_clause) _可选_ [*参数从句*](../chapter3/05_Declarations.html#parameter_clause) [*构造器主体*](../chapter3/05_Declarations.html#initializer_body) -> *构造器头(Head)* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*声明修改器集(declaration-modifiers)*](TODO) _可选_ **init** -> *构造器头(Head)* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*声明修改器集(declaration-modifiers)*](TODO) _可选_ **init ?** -> *构造器头(Head)* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*声明修改器集(declaration-modifiers)*](TODO) _可选_ **init !** -> *构造器主体* → [*代码块*](../chapter3/05_Declarations.html#code_block) +> *构造器声明* → [*构造器头(Head)*](../chapter3/05_Declarations.html#initializer_head) [*泛型参数从句*](GenericParametersAndArguments.html#generic_parameter_clause) _可选_ [*参数从句*](../chapter3/05_Declarations.html#parameter_clause) [*构造器主体*](../chapter3/05_Declarations.html#initializer_body) +> *构造器头(Head)* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*声明修改器集(declaration-modifiers)*](TODO) _可选_ **init** +> *构造器头(Head)* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*声明修改器集(declaration-modifiers)*](TODO) _可选_ **init ?** +> *构造器头(Head)* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*声明修改器集(declaration-modifiers)*](TODO) _可选_ **init !** +> *构造器主体* → [*代码块*](../chapter3/05_Declarations.html#code_block) -> 析构器声明语法 +> 析构器声明语法 > > *析构器声明* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ **deinit** [*代码块*](../chapter3/05_Declarations.html#code_block) -> 扩展(Extension)声明语法 +> 扩展(Extension)声明语法 > -> *扩展声明* → [*访问级别修改器*](TODO) _可选_ **extension** [*类型标识*](../chapter3/03_Types.html#type_identifier) [*类型继承从句*](../chapter3/03_Types.html#type_inheritance_clause) _可选_ [*extension-body*](../chapter3/05_Declarations.html#extension_body) +> *扩展声明* → [*访问级别修改器*](TODO) _可选_ **extension** [*类型标识*](../chapter3/03_Types.html#type_identifier) [*类型继承从句*](../chapter3/03_Types.html#type_inheritance_clause) _可选_ [*extension-body*](../chapter3/05_Declarations.html#extension_body) > *extension-body* → **{** [*声明(Declarations)集*](../chapter3/05_Declarations.html#declarations) _可选_ **}** -> 下标声明语法 +> 下标声明语法 > -> *下标声明* → [*下标头(Head)*](../chapter3/05_Declarations.html#subscript_head) [*下标结果(Result)*](../chapter3/05_Declarations.html#subscript_result) [*代码块*](../chapter3/05_Declarations.html#code_block) -> *下标声明* → [*下标头(Head)*](../chapter3/05_Declarations.html#subscript_head) [*下标结果(Result)*](../chapter3/05_Declarations.html#subscript_result) [*getter-setter 块*](../chapter3/05_Declarations.html#getter_setter_block) -> *下标声明* → [*下标头(Head)*](../chapter3/05_Declarations.html#subscript_head) [*下标结果(Result)*](../chapter3/05_Declarations.html#subscript_result) [*getter-setter 关键字(Keyword)块*](../chapter3/05_Declarations.html#getter_setter_keyword_block) -> *下标头(Head)* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*声明修改器(declaration-modifiers)*](TODO) _可选_ **subscript** [*参数从句*](../chapter3/05_Declarations.html#parameter_clause) -> *下标结果(Result)* → **->** [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*类型*](../chapter3/03_Types.html#type) +> *下标声明* → [*下标头(Head)*](../chapter3/05_Declarations.html#subscript_head) [*下标结果(Result)*](../chapter3/05_Declarations.html#subscript_result) [*代码块*](../chapter3/05_Declarations.html#code_block) +> *下标声明* → [*下标头(Head)*](../chapter3/05_Declarations.html#subscript_head) [*下标结果(Result)*](../chapter3/05_Declarations.html#subscript_result) [*getter-setter 块*](../chapter3/05_Declarations.html#getter_setter_block) +> *下标声明* → [*下标头(Head)*](../chapter3/05_Declarations.html#subscript_head) [*下标结果(Result)*](../chapter3/05_Declarations.html#subscript_result) [*getter-setter 关键字(Keyword)块*](../chapter3/05_Declarations.html#getter_setter_keyword_block) +> *下标头(Head)* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*声明修改器(declaration-modifiers)*](TODO) _可选_ **subscript** [*参数从句*](../chapter3/05_Declarations.html#parameter_clause) +> *下标结果(Result)* → **->** [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*类型*](../chapter3/03_Types.html#type) -> 运算符声明语法 +> 运算符声明语法 > -> *运算符声明* → [*前置运算符声明*](../chapter3/05_Declarations.html#prefix_operator_declaration) | [*后置运算符声明*](../chapter3/05_Declarations.html#postfix_operator_declaration) | [*中置运算符声明*](../chapter3/05_Declarations.html#infix_operator_declaration) -> *前置运算符声明* → **prefix** **运算符** [*运算符*](../chapter3/02_Lexical_Structure.html#operator) **{** **}** -> *后置运算符声明* → **postfix** **运算符** [*运算符*](../chapter3/02_Lexical_Structure.html#operator) **{** **}** -> *中置运算符声明* → **infix** **运算符** [*运算符*](../chapter3/02_Lexical_Structure.html#operator) **{** [*中置运算符属性集*](../chapter3/05_Declarations.html#infix_operator_attributes) _可选_ **}** -> *中置运算符属性集* → [*优先级从句*](../chapter3/05_Declarations.html#precedence_clause) _可选_ [*结和性从句*](../chapter3/05_Declarations.html#associativity_clause) _可选_ -> *优先级从句* → **precedence** [*优先级水平*](../chapter3/05_Declarations.html#precedence_level) -> *优先级水平* → 数值 0 到 255,首末项包括在内 -> *结和性从句* → **associativity** [*结和性*](../chapter3/05_Declarations.html#associativity) -> *结和性* → **left** | **right** | **none** +> *运算符声明* → [*前置运算符声明*](../chapter3/05_Declarations.html#prefix_operator_declaration) | [*后置运算符声明*](../chapter3/05_Declarations.html#postfix_operator_declaration) | [*中置运算符声明*](../chapter3/05_Declarations.html#infix_operator_declaration) +> *前置运算符声明* → **prefix** **运算符** [*运算符*](../chapter3/02_Lexical_Structure.html#operator) **{** **}** +> *后置运算符声明* → **postfix** **运算符** [*运算符*](../chapter3/02_Lexical_Structure.html#operator) **{** **}** +> *中置运算符声明* → **infix** **运算符** [*运算符*](../chapter3/02_Lexical_Structure.html#operator) **{** [*中置运算符属性集*](../chapter3/05_Declarations.html#infix_operator_attributes) _可选_ **}** +> *中置运算符属性集* → [*优先级从句*](../chapter3/05_Declarations.html#precedence_clause) _可选_ [*结和性从句*](../chapter3/05_Declarations.html#associativity_clause) _可选_ +> *优先级从句* → **precedence** [*优先级水平*](../chapter3/05_Declarations.html#precedence_level) +> *优先级水平* → 数值 0 到 255,首末项包括在内 +> *结和性从句* → **associativity** [*结和性*](../chapter3/05_Declarations.html#associativity) +> *结和性* → **left** | **right** | **none** -> 声明修改器语法 +> 声明修改器语法 > -> *声明修改器* → **类** | **便捷(convenience)** | **动态(dynamic)** | **final** | **中置(infix)** | **lazy** | **可变(mutating)** | **不可变(nonmutating)** | **可选(optional)** | **改写(override)** | **后置** | **前置** | **required** | **static** | **unowned** | **unowned(safe)** | **unowned(unsafe)** | **弱(weak)** -> *声明修改器* → [*访问级别声明器(access-level-modifier)*](TODO) -> *声明修改集* → [*声明修改器*](TODO) [*声明修改器集*](TODO) _可选_ -> *访问级别修改器* → **内部的** | **内部的(set)** -> *访问级别修改器* → **私有的** | **私有的(set)** -> *访问级别修改器* → **公共的** -| **公共的(set)** -> *访问级别修改器集* →[*访问级别修改器*](TODO) [*访问级别修改器集*](TODO) _可选_ +> *声明修改器* → **类** | **便捷(convenience)** | **动态(dynamic)** | **final** | **中置(infix)** | **lazy** | **可变(mutating)** | **不可变(nonmutating)** | **可选(optional)** | **改写(override)** | **后置** | **前置** | **required** | **static** | **unowned** | **unowned(safe)** | **unowned(unsafe)** | **弱(weak)** +> *声明修改器* → [*访问级别声明器(access-level-modifier)*](TODO) +> *声明修改集* → [*声明修改器*](TODO) [*声明修改器集*](TODO) _可选_ +> *访问级别修改器* → **内部的** | **内部的(set)** +> *访问级别修改器* → **私有的** | **私有的(set)** +> *访问级别修改器* → **公共的** +| **公共的(set)** +> *访问级别修改器集* →[*访问级别修改器*](TODO) [*访问级别修改器集*](TODO) _可选_ ## 模式 -> 模式(Patterns) 语法 +> 模式(Patterns) 语法 > -> *模式* → [*通配符模式*](../chapter3/07_Patterns.html#wildcard_pattern) [*类型注解*](../chapter3/03_Types.html#type_annotation) _可选_ -> *模式* → [*标识符模式*](../chapter3/07_Patterns.html#identifier_pattern) [*类型注解*](../chapter3/03_Types.html#type_annotati Value Bindingon ) _可选_ -> *模式* → [*值绑定模式*](../chapter3/07_Patterns.html#value_binding_pattern) -> *模式* → [*元组模式*](../chapter3/07_Patterns.html#tuple_pattern) [*类型注解*](../chapter3/03_Types.html#type_annotation) _可选_ +> *模式* → [*通配符模式*](../chapter3/07_Patterns.html#wildcard_pattern) [*类型注解*](../chapter3/03_Types.html#type_annotation) _可选_ +> *模式* → [*标识符模式*](../chapter3/07_Patterns.html#identifier_pattern) [*类型注解*](../chapter3/03_Types.html#type_annotati Value Bindingon ) _可选_ +> *模式* → [*值绑定模式*](../chapter3/07_Patterns.html#value_binding_pattern) +> *模式* → [*元组模式*](../chapter3/07_Patterns.html#tuple_pattern) [*类型注解*](../chapter3/03_Types.html#type_annotation) _可选_ > -> *模式* → [*枚举个例模式*](../chapter3/07_Patterns.html#enum_case_pattern) -> *模式* → [*可选模式*](TODO) -> *模式* → [*类型转换模式*](../chapter3/07_Patterns.html#type_casting_pattern) -> *模式* → [*表达式模式*](../chapter3/07_Patterns.html#expression_pattern) +> *模式* → [*枚举个例模式*](../chapter3/07_Patterns.html#enum_case_pattern) +> *模式* → [*可选模式*](TODO) +> *模式* → [*类型转换模式*](../chapter3/07_Patterns.html#type_casting_pattern) +> *模式* → [*表达式模式*](../chapter3/07_Patterns.html#expression_pattern) -> 通配符模式语法 +> 通配符模式语法 > > *通配符模式* → **_** -> 标识符模式语法 +> 标识符模式语法 > > *标识符模式* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) -> 值绑定(Value Binding)模式语法 +> 值绑定(Value Binding)模式语法 > > *值绑定模式* → **var** [*模式*](../chapter3/07_Patterns.html#pattern) | **let** [*模式*](../chapter3/07_Patterns.html#pattern) -> 元组模式语法 +> 元组模式语法 > -> *元组模式* → **(** [*元组模式元素集*](../chapter3/07_Patterns.html#tuple_pattern_element_list) _可选_ **)** -> *元组模式元素集* → [*元组模式元素*](../chapter3/07_Patterns.html#tuple_pattern_element) | [*元组模式元素*](../chapter3/07_Patterns.html#tuple_pattern_element) **,** [*元组模式元素集*](../chapter3/07_Patterns.html#tuple_pattern_element_list) +> *元组模式* → **(** [*元组模式元素集*](../chapter3/07_Patterns.html#tuple_pattern_element_list) _可选_ **)** +> *元组模式元素集* → [*元组模式元素*](../chapter3/07_Patterns.html#tuple_pattern_element) | [*元组模式元素*](../chapter3/07_Patterns.html#tuple_pattern_element) **,** [*元组模式元素集*](../chapter3/07_Patterns.html#tuple_pattern_element_list) > *元组模式元素* → [*模式*](../chapter3/07_Patterns.html#pattern) -> 枚举用例模式语法 +> 枚举用例模式语法 > -> *enum-case-pattern* → [*类型标识*](../chapter3/03_Types.html#type_identifier) _可选_ **.** [*枚举的 case 名*](../chapter3/05_Declarations.html#enum_case_name) [*元组模式*](../chapter3/07_Patterns.html#tuple_pattern) _可选_ +> *enum-case-pattern* → [*类型标识*](../chapter3/03_Types.html#type_identifier) _可选_ **.** [*枚举的 case 名*](../chapter3/05_Declarations.html#enum_case_name) [*元组模式*](../chapter3/07_Patterns.html#tuple_pattern) _可选_ -> 可选模式语法 +> 可选模式语法 > > *可选模式* → [*识别符模式*](TODO) **?** -> 类型转换模式语法 +> 类型转换模式语法 > -> *类型转换模式(type-casting-pattern)* → [*is 模式*](../chapter3/07_Patterns.html#is_pattern) | [*as 模式*](../chapter3/07_Patterns.html#as_pattern) -> *is 模式* → **is** [*类型*](../chapter3/03_Types.html#type) +> *类型转换模式(type-casting-pattern)* → [*is 模式*](../chapter3/07_Patterns.html#is_pattern) | [*as 模式*](../chapter3/07_Patterns.html#as_pattern) +> *is 模式* → **is** [*类型*](../chapter3/03_Types.html#type) > *as 模式* → [*模式*](../chapter3/07_Patterns.html#pattern) **as** [*类型*](../chapter3/03_Types.html#type) -> 表达式模式语法 +> 表达式模式语法 > > *表达式模式* → [*表达式*](../chapter3/04_Expressions.html#expression) ## 属性 -> 属性语法 +> 属性语法 > -> *属性* → **@** [*属性名*](../chapter3/06_Attributes.html#attribute_name) [*属性参数从句*](../chapter3/06_Attributes.html#attribute_argument_clause) _可选_ +> *属性* → **@** [*属性名*](../chapter3/06_Attributes.html#attribute_name) [*属性参数从句*](../chapter3/06_Attributes.html#attribute_argument_clause) _可选_ > *属性名* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) -> *属性参数从句* → **(** [*平衡令牌集*](../chapter3/06_Attributes.html#balanced_tokens) _可选_ **)** -> *属性(Attributes)集* → [*属性*](../chapter3/06_Attributes.html#attribute) [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ -> *平衡令牌集* → [*平衡令牌*](../chapter3/06_Attributes.html#balanced_token) [*平衡令牌集*](../chapter3/06_Attributes.html#balanced_tokens) _可选_ -> *平衡令牌* → **(** [*平衡令牌集*](../chapter3/06_Attributes.html#balanced_tokens) _可选_ **)** -> *平衡令牌* → **[** [*平衡令牌集*](../chapter3/06_Attributes.html#balanced_tokens) _可选_ **]** -> *平衡令牌* → **{** [*平衡令牌集*](../chapter3/06_Attributes.html#balanced_tokens) _可选_ **}** -> *平衡令牌* → **任意标识符、关键字、字面量或运算符** +> *属性参数从句* → **(** [*平衡令牌集*](../chapter3/06_Attributes.html#balanced_tokens) _可选_ **)** +> *属性(Attributes)集* → [*属性*](../chapter3/06_Attributes.html#attribute) [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ +> *平衡令牌集* → [*平衡令牌*](../chapter3/06_Attributes.html#balanced_token) [*平衡令牌集*](../chapter3/06_Attributes.html#balanced_tokens) _可选_ +> *平衡令牌* → **(** [*平衡令牌集*](../chapter3/06_Attributes.html#balanced_tokens) _可选_ **)** +> *平衡令牌* → **[** [*平衡令牌集*](../chapter3/06_Attributes.html#balanced_tokens) _可选_ **]** +> *平衡令牌* → **{** [*平衡令牌集*](../chapter3/06_Attributes.html#balanced_tokens) _可选_ **}** +> *平衡令牌* → **任意标识符、关键字、字面量或运算符** > *平衡令牌* → **任意标点除了(, )、[, ]、{, 或 }** ## 表达式 -> 表达式语法 +> 表达式语法 > -> *表达式* → [*try-operator*](TODO) _可选_ [*前置表达式*](../chapter3/04_Expressions.html#prefix_expression) [*二元表达式集*](../chapter3/04_Expressions.html#binary_expressions) _可选_ -> *表达式集* → [*表达式*](../chapter3/04_Expressions.html#expression) | [*表达式*](../chapter3/04_Expressions.html#expression) **,** [*表达式集*](../chapter3/04_Expressions.html#expression_list) +> *表达式* → [*try-operator*](TODO) _可选_ [*前置表达式*](../chapter3/04_Expressions.html#prefix_expression) [*二元表达式集*](../chapter3/04_Expressions.html#binary_expressions) _可选_ +> *表达式集* → [*表达式*](../chapter3/04_Expressions.html#expression) | [*表达式*](../chapter3/04_Expressions.html#expression) **,** [*表达式集*](../chapter3/04_Expressions.html#expression_list) -> 前置表达式语法 +> 前置表达式语法 > -> *前置表达式* → [*前置运算符*](../chapter3/02_Lexical_Structure.html#prefix_operator) _可选_ [*后置表达式*](../chapter3/04_Expressions.html#postfix_expression) -> *前置表达式* → [*写入写出(in-out)表达式*](../chapter3/04_Expressions.html#in_out_expression) -> *写入写出(in-out)表达式* → **&** [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) +> *前置表达式* → [*前置运算符*](../chapter3/02_Lexical_Structure.html#prefix_operator) _可选_ [*后置表达式*](../chapter3/04_Expressions.html#postfix_expression) +> *前置表达式* → [*写入写出(in-out)表达式*](../chapter3/04_Expressions.html#in_out_expression) +> *写入写出(in-out)表达式* → **&** [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) -> try 表达式语法 +> try 表达式语法 > > *try-operator* → **try** | **try !** -> 二元表达式语法 +> 二元表达式语法 > -> *二元表达式* → [*二元运算符*](../chapter3/02_Lexical_Structure.html#binary_operator) [*前置表达式*](../chapter3/04_Expressions.html#prefix_expression) -> *二元表达式* → [*赋值运算符*](../chapter3/04_Expressions.html#assignment_operator) [*try 运算符*](TODO) _可选_ [*前置表达式*](../chapter3/04_Expressions.html#prefix_expression) -> *二元表达式* → [*条件运算符*](../chapter3/04_Expressions.html#conditional_operator) [*try 运算符*](TODO) _可选_ [*前置表达式*](../chapter3/04_Expressions.html#prefix_expression) -> *二元表达式* → [*类型转换运算符*](../chapter3/04_Expressions.html#type_casting_operator) +> *二元表达式* → [*二元运算符*](../chapter3/02_Lexical_Structure.html#binary_operator) [*前置表达式*](../chapter3/04_Expressions.html#prefix_expression) +> *二元表达式* → [*赋值运算符*](../chapter3/04_Expressions.html#assignment_operator) [*try 运算符*](TODO) _可选_ [*前置表达式*](../chapter3/04_Expressions.html#prefix_expression) +> *二元表达式* → [*条件运算符*](../chapter3/04_Expressions.html#conditional_operator) [*try 运算符*](TODO) _可选_ [*前置表达式*](../chapter3/04_Expressions.html#prefix_expression) +> *二元表达式* → [*类型转换运算符*](../chapter3/04_Expressions.html#type_casting_operator) > *二元表达式集* → [*二元表达式*](../chapter3/04_Expressions.html#binary_expression) [*二元表达式集*](../chapter3/04_Expressions.html#binary_expressions) _可选_ -> 赋值运算符语法 +> 赋值运算符语法 > > *赋值运算符* → **=** -> 三元条件运算符语法 +> 三元条件运算符语法 > > *三元条件运算符* → **?** [*表达式*](../chapter3/04_Expressions.html#expression) **:** -> 类型转换运算符语法 +> 类型转换运算符语法 > -> *类型转换运算符* → **is** [*类型*](../chapter3/03_Types.html#type) -> *类型转换运算符* → **as** [*类型*](../chapter3/03_Types.html#type) -> *类型转换运算符* → **as ?** [*类型*](../chapter3/03_Types.html#type) -> *类型转换运算符* → **as !** [*类型*](../chapter3/03_Types.html#type) +> *类型转换运算符* → **is** [*类型*](../chapter3/03_Types.html#type) +> *类型转换运算符* → **as** [*类型*](../chapter3/03_Types.html#type) +> *类型转换运算符* → **as ?** [*类型*](../chapter3/03_Types.html#type) +> *类型转换运算符* → **as !** [*类型*](../chapter3/03_Types.html#type) -> 主表达式语法 +> 主表达式语法 > -> *主表达式* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) [*泛型参数从句*](GenericParametersAndArguments.html#generic_argument_clause) _可选_ -> *主表达式* → [*字面量表达式*](../chapter3/04_Expressions.html#literal_expression) -> *主表达式* → [*self 表达式*](../chapter3/04_Expressions.html#self_expression) -> *主表达式* → [*超类表达式*](../chapter3/04_Expressions.html#superclass_expression) -> *主表达式* → [*闭包表达式*](../chapter3/04_Expressions.html#closure_expression) -> *主表达式* → [*圆括号表达式*](../chapter3/04_Expressions.html#parenthesized_expression) -> *主表达式* → [*隐式成员表达式*](../chapter3/04_Expressions.html#implicit_member_expression) +> *主表达式* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) [*泛型参数从句*](GenericParametersAndArguments.html#generic_argument_clause) _可选_ +> *主表达式* → [*字面量表达式*](../chapter3/04_Expressions.html#literal_expression) +> *主表达式* → [*self 表达式*](../chapter3/04_Expressions.html#self_expression) +> *主表达式* → [*超类表达式*](../chapter3/04_Expressions.html#superclass_expression) +> *主表达式* → [*闭包表达式*](../chapter3/04_Expressions.html#closure_expression) +> *主表达式* → [*圆括号表达式*](../chapter3/04_Expressions.html#parenthesized_expression) +> *主表达式* → [*隐式成员表达式*](../chapter3/04_Expressions.html#implicit_member_expression) > *主表达式* → [*通配符表达式*](../chapter3/04_Expressions.html#wildcard_expression) -> 字面量表达式语法 +> 字面量表达式语法 > -> *字面量表达式* → [*字面量*](../chapter3/02_Lexical_Structure.html#literal) -> *字面量表达式* → [*数组字面量*](../chapter3/04_Expressions.html#array_literal) | [*字典字面量*](../chapter3/04_Expressions.html#dictionary_literal) -> *字面量表达式* → **__FILE__** | **__LINE__** | **__COLUMN__** | **__FUNCTION__** -> *数组字面量* → **[** [*数组字面量项集*](../chapter3/04_Expressions.html#array_literal_items) _可选_ **]** -> *数组字面量项集* → [*数组字面量项*](../chapter3/04_Expressions.html#array_literal_item) **,** _可选_ | [*数组字面量项*](../chapter3/04_Expressions.html#array_literal_item) **,** [*数组字面量项集*](../chapter3/04_Expressions.html#array_literal_items) -> *数组字面量项* → [*表达式*](../chapter3/04_Expressions.html#expression) -> *字典字面量* → **[** [*字典字面量项集*](../chapter3/04_Expressions.html#dictionary_literal_items) **]** | **[** **:** **]** -> *字典字面量项集* → [*字典字面量项*](../chapter3/04_Expressions.html#dictionary_literal_item) **,** _可选_ | [*字典字面量项*](../chapter3/04_Expressions.html#dictionary_literal_item) **,** [*字典字面量项集*](../chapter3/04_Expressions.html#dictionary_literal_items) -> *字典字面量项* → [*表达式*](../chapter3/04_Expressions.html#expression) **:** [*表达式*](../chapter3/04_Expressions.html#expression) +> *字面量表达式* → [*字面量*](../chapter3/02_Lexical_Structure.html#literal) +> *字面量表达式* → [*数组字面量*](../chapter3/04_Expressions.html#array_literal) | [*字典字面量*](../chapter3/04_Expressions.html#dictionary_literal) +> *字面量表达式* → **__FILE__** | **__LINE__** | **__COLUMN__** | **__FUNCTION__** +> *数组字面量* → **[** [*数组字面量项集*](../chapter3/04_Expressions.html#array_literal_items) _可选_ **]** +> *数组字面量项集* → [*数组字面量项*](../chapter3/04_Expressions.html#array_literal_item) **,** _可选_ | [*数组字面量项*](../chapter3/04_Expressions.html#array_literal_item) **,** [*数组字面量项集*](../chapter3/04_Expressions.html#array_literal_items) +> *数组字面量项* → [*表达式*](../chapter3/04_Expressions.html#expression) +> *字典字面量* → **[** [*字典字面量项集*](../chapter3/04_Expressions.html#dictionary_literal_items) **]** | **[** **:** **]** +> *字典字面量项集* → [*字典字面量项*](../chapter3/04_Expressions.html#dictionary_literal_item) **,** _可选_ | [*字典字面量项*](../chapter3/04_Expressions.html#dictionary_literal_item) **,** [*字典字面量项集*](../chapter3/04_Expressions.html#dictionary_literal_items) +> *字典字面量项* → [*表达式*](../chapter3/04_Expressions.html#expression) **:** [*表达式*](../chapter3/04_Expressions.html#expression) -> Self 表达式语法 +> Self 表达式语法 > -> *self 表达式* → **self** -> *self 表达式* → **self** **.** [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) -> *self 表达式* → **self** **[** [*表达式*](../chapter3/04_Expressions.html#expression) **]** -> *self 表达式* → **self** **.** **init** +> *self 表达式* → **self** +> *self 表达式* → **self** **.** [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) +> *self 表达式* → **self** **[** [*表达式*](../chapter3/04_Expressions.html#expression) **]** +> *self 表达式* → **self** **.** **init** -> 超类表达式语法 +> 超类表达式语法 > -> *超类表达式* → [*超类方法表达式*](../chapter3/04_Expressions.html#superclass_method_expression) | [*超类下标表达式*](../chapter3/04_Expressions.html#超类下标表达式) | [*超类构造器表达式*](../chapter3/04_Expressions.html#superclass_initializer_expression) -> *超类方法表达式* → **super** **.** [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) -> *超类下标表达式* → **super** **[** [*表达式*](../chapter3/04_Expressions.html#expression) **]** -> *超类构造器表达式* → **super** **.** **init** +> *超类表达式* → [*超类方法表达式*](../chapter3/04_Expressions.html#superclass_method_expression) | [*超类下标表达式*](../chapter3/04_Expressions.html#超类下标表达式) | [*超类构造器表达式*](../chapter3/04_Expressions.html#superclass_initializer_expression) +> *超类方法表达式* → **super** **.** [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) +> *超类下标表达式* → **super** **[** [*表达式*](../chapter3/04_Expressions.html#expression) **]** +> *超类构造器表达式* → **super** **.** **init** -> 闭包表达式语法 +> 闭包表达式语法 > -> *闭包表达式* → **{** [*闭包签名(Signational)*](../chapter3/04_Expressions.html#closure_signature) _可选_ [*多条语句(Statements)*](../chapter3/10_Statements.html#statements) **}** -> *闭包签名(Signational)* → [*参数从句*](../chapter3/05_Declarations.html#parameter_clause) [*函数结果*](../chapter3/05_Declarations.html#function_result) _可选_ **in** -> *闭包签名(Signational)* → [*标识符集*](../chapter3/02_Lexical_Structure.html#identifier_list) [*函数结果*](../chapter3/05_Declarations.html#function_result) _可选_ **in** -> *闭包签名(Signational)* → [*捕获(Capature)集*](../chapter3/04_Expressions.html#capture_list) [*参数从句*](../chapter3/05_Declarations.html#parameter_clause) [*函数结果*](../chapter3/05_Declarations.html#function_result) _可选_ **in** -> *闭包签名(Signational)* → [*捕获(Capature)集*](../chapter3/04_Expressions.html#capture_list) [*标识符集*](../chapter3/02_Lexical_Structure.html#identifier_list) [*函数结果*](../chapter3/05_Declarations.html#function_result) _可选_ **in** -> *闭包签名(Signational)* → [*捕获(Capature)集*](../chapter3/04_Expressions.html#capture_list) **in** -> *捕获(Capature)集* → **[** [*捕获(Capature)说明符*](../chapter3/04_Expressions.html#capture_specifier) [*表达式*](../chapter3/04_Expressions.html#expression) **]** -> *捕获(Capature)说明符* → **weak** | **unowned** | **unowned(safe)** | **unowned(unsafe)** +> *闭包表达式* → **{** [*闭包签名(Signational)*](../chapter3/04_Expressions.html#closure_signature) _可选_ [*多条语句(Statements)*](../chapter3/10_Statements.html#statements) **}** +> *闭包签名(Signational)* → [*参数从句*](../chapter3/05_Declarations.html#parameter_clause) [*函数结果*](../chapter3/05_Declarations.html#function_result) _可选_ **in** +> *闭包签名(Signational)* → [*标识符集*](../chapter3/02_Lexical_Structure.html#identifier_list) [*函数结果*](../chapter3/05_Declarations.html#function_result) _可选_ **in** +> *闭包签名(Signational)* → [*捕获(Capature)集*](../chapter3/04_Expressions.html#capture_list) [*参数从句*](../chapter3/05_Declarations.html#parameter_clause) [*函数结果*](../chapter3/05_Declarations.html#function_result) _可选_ **in** +> *闭包签名(Signational)* → [*捕获(Capature)集*](../chapter3/04_Expressions.html#capture_list) [*标识符集*](../chapter3/02_Lexical_Structure.html#identifier_list) [*函数结果*](../chapter3/05_Declarations.html#function_result) _可选_ **in** +> *闭包签名(Signational)* → [*捕获(Capature)集*](../chapter3/04_Expressions.html#capture_list) **in** +> *捕获(Capature)集* → **[** [*捕获(Capature)说明符*](../chapter3/04_Expressions.html#capture_specifier) [*表达式*](../chapter3/04_Expressions.html#expression) **]** +> *捕获(Capature)说明符* → **weak** | **unowned** | **unowned(safe)** | **unowned(unsafe)** -> 隐式成员表达式语法 +> 隐式成员表达式语法 > > *隐式成员表达式* → **.** [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) -> 圆括号表达式(Parenthesized Expression)语法 +> 圆括号表达式(Parenthesized Expression)语法 > -> *圆括号表达式* → **(** [*表达式元素集*](../chapter3/04_Expressions.html#expression_element_list) _可选_ **)** -> *表达式元素集* → [*表达式元素*](../chapter3/04_Expressions.html#expression_element) | [*表达式元素*](../chapter3/04_Expressions.html#expression_element) **,** [*表达式元素集*](../chapter3/04_Expressions.html#expression_element_list) +> *圆括号表达式* → **(** [*表达式元素集*](../chapter3/04_Expressions.html#expression_element_list) _可选_ **)** +> *表达式元素集* → [*表达式元素*](../chapter3/04_Expressions.html#expression_element) | [*表达式元素*](../chapter3/04_Expressions.html#expression_element) **,** [*表达式元素集*](../chapter3/04_Expressions.html#expression_element_list) > *表达式元素* → [*表达式*](../chapter3/04_Expressions.html#expression) | [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) **:** [*表达式*](../chapter3/04_Expressions.html#expression) -> 通配符表达式语法 +> 通配符表达式语法 > > *通配符表达式* → **_** -> 后置表达式语法 +> 后置表达式语法 > -> *后置表达式* → [*主表达式*](../chapter3/04_Expressions.html#primary_expression) -> *后置表达式* → [*后置表达式*](../chapter3/04_Expressions.html#postfix_expression) [*后置运算符*](../chapter3/02_Lexical_Structure.html#postfix_operator) -> *后置表达式* → [*函数调用表达式*](../chapter3/04_Expressions.html#function_call_expression) -> *后置表达式* → [*构造器表达式*](../chapter3/04_Expressions.html#initializer_expression) -> *后置表达式* → [*显示成员表达式*](../chapter3/04_Expressions.html#explicit_member_expression) -> *后置表达式* → [*后置 self 表达式*](../chapter3/04_Expressions.html#postfix_self_expression) -> *后置表达式* → [*动态类型表达式*](../chapter3/04_Expressions.html#dynamic_type_expression) -> *后置表达式* → [*下标表达式*](../chapter3/04_Expressions.html#subscript_expression) -> *后置表达式* → [*强制取值(Forced Value)表达式*](../chapter3/04_Expressions.html#forced_value_expression) +> *后置表达式* → [*主表达式*](../chapter3/04_Expressions.html#primary_expression) +> *后置表达式* → [*后置表达式*](../chapter3/04_Expressions.html#postfix_expression) [*后置运算符*](../chapter3/02_Lexical_Structure.html#postfix_operator) +> *后置表达式* → [*函数调用表达式*](../chapter3/04_Expressions.html#function_call_expression) +> *后置表达式* → [*构造器表达式*](../chapter3/04_Expressions.html#initializer_expression) +> *后置表达式* → [*显示成员表达式*](../chapter3/04_Expressions.html#explicit_member_expression) +> *后置表达式* → [*后置 self 表达式*](../chapter3/04_Expressions.html#postfix_self_expression) +> *后置表达式* → [*动态类型表达式*](../chapter3/04_Expressions.html#dynamic_type_expression) +> *后置表达式* → [*下标表达式*](../chapter3/04_Expressions.html#subscript_expression) +> *后置表达式* → [*强制取值(Forced Value)表达式*](../chapter3/04_Expressions.html#forced_value_expression) > *后置表达式* → [*可选链(Optional Chaining)表达式*](../chapter3/04_Expressions.html#optional_chaining_expression) -> 函数调用表达式语法 +> 函数调用表达式语法 > -> *函数调用表达式* → [*后置表达式*](../chapter3/04_Expressions.html#postfix_expression) [*圆括号表达式*](../chapter3/04_Expressions.html#parenthesized_expression) +> *函数调用表达式* → [*后置表达式*](../chapter3/04_Expressions.html#postfix_expression) [*圆括号表达式*](../chapter3/04_Expressions.html#parenthesized_expression) > *函数调用表达式* → [*后置表达式*](../chapter3/04_Expressions.html#postfix_expression) [*圆括号表达式*](../chapter3/04_Expressions.html#parenthesized_expression) _可选_ [*后置闭包(Trailing Closure)*](../chapter3/04_Expressions.html#trailing_closure) -> *后置闭包(Trailing Closure)* → [*闭包表达式*](../chapter3/04_Expressions.html#closure_expression) +> *后置闭包(Trailing Closure)* → [*闭包表达式*](../chapter3/04_Expressions.html#closure_expression) -> 构造器表达式语法 +> 构造器表达式语法 > > *构造器表达式* → [*后置表达式*](../chapter3/04_Expressions.html#postfix_expression) **.** **init** -> 显式成员表达式语法 +> 显式成员表达式语法 > -> *显示成员表达式* → [*后置表达式*](../chapter3/04_Expressions.html#postfix_expression) **.** [*十进制数字*](../chapter3/02_Lexical_Structure.html#decimal_digit) +> *显示成员表达式* → [*后置表达式*](../chapter3/04_Expressions.html#postfix_expression) **.** [*十进制数字*](../chapter3/02_Lexical_Structure.html#decimal_digit) > *显示成员表达式* → [*后置表达式*](../chapter3/04_Expressions.html#postfix_expression) **.** [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) [*泛型参数从句*](GenericParametersAndArguments.html#generic_argument_clause) _可选_ -> 后置 Self 表达式语法 +> 后置 Self 表达式语法 > > *后置 self 表达式* → [*后置表达式*](../chapter3/04_Expressions.html#postfix_expression) **.** **self** -> 动态类型表达式语法 +> 动态类型表达式语法 > > *动态类型表达式* → [*后置表达式*](../chapter3/04_Expressions.html#postfix_expression) **.** **dynamicType** -> 附属脚本表达式语法 +> 附属脚本表达式语法 > > *附属脚本表达式* → [*后置表达式*](../chapter3/04_Expressions.html#postfix_expression) **[** [*表达式集*](../chapter3/04_Expressions.html#expression_list) **]** -> 强制取值(Forced Value)语法 +> 强制取值(Forced Value)语法 > > *强制取值(Forced Value)表达式* → [*后置表达式*](../chapter3/04_Expressions.html#postfix_expression) **!** -> 可选链表达式语法 +> 可选链表达式语法 > > *可选链表达式* → [*后置表达式*](../chapter3/04_Expressions.html#postfix_expression) **?** ## 词法结构 -> 标识符语法 +> 标识符语法 > -> *标识符* → [*标识符头(Head)*](../chapter3/02_Lexical_Structure.html#identifier_head) [*标识符字符集*](../chapter3/02_Lexical_Structure.html#identifier_characters) _可选_ -> *标识符* → [*标识符头(Head)*](../chapter3/02_Lexical_Structure.html#identifier_head) [*标识符字符集*](../chapter3/02_Lexical_Structure.html#identifier_characters) _可选_ -> *标识符* → [*隐式参数名*](../chapter3/02_Lexical_Structure.html#implicit_parameter_name) -> *标识符集* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) | [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) **,** [*标识符集*](../chapter3/02_Lexical_Structure.html#identifier_list) -> *标识符头(Head)* → Upper- or lowercase letter A through Z -> *标识符头(Head)* → _ -> *标识符头(Head)* → U+00A8, U+00AA, U+00AD, U+00AF, U+00B2–U+00B5, or U+00B7–U+00BA -> *标识符头(Head)* → U+00BC–U+00BE, U+00C0–U+00D6, U+00D8–U+00F6, or U+00F8–U+00FF -> *标识符头(Head)* → U+0100–U+02FF, U+0370–U+167F, U+1681–U+180D, or U+180F–U+1DBF -> *标识符头(Head)* → U+1E00–U+1FFF -> *标识符头(Head)* → U+200B–U+200D, U+202A–U+202E, U+203F–U+2040, U+2054, or U+2060–U+206F -> *标识符头(Head)* → U+2070–U+20CF, U+2100–U+218F, U+2460–U+24FF, or U+2776–U+2793 -> *标识符头(Head)* → U+2C00–U+2DFF or U+2E80–U+2FFF -> *标识符头(Head)* → U+3004–U+3007, U+3021–U+302F, U+3031–U+303F, or U+3040–U+D7FF -> *标识符头(Head)* → U+F900–U+FD3D, U+FD40–U+FDCF, U+FDF0–U+FE1F, or U+FE30–U+FE44 -> *标识符头(Head)* → U+FE47–U+FFFD -> *标识符头(Head)* → U+10000–U+1FFFD, U+20000–U+2FFFD, U+30000–U+3FFFD, or U+40000–U+4FFFD -> *标识符头(Head)* → U+50000–U+5FFFD, U+60000–U+6FFFD, U+70000–U+7FFFD, or U+80000–U+8FFFD -> *标识符头(Head)* → U+90000–U+9FFFD, U+A0000–U+AFFFD, U+B0000–U+BFFFD, or U+C0000–U+CFFFD -> *标识符头(Head)* → U+D0000–U+DFFFD or U+E0000–U+EFFFD -> *标识符字符* → 数值 0 到 9 -> *标识符字符* → U+0300–U+036F, U+1DC0–U+1DFF, U+20D0–U+20FF, or U+FE20–U+FE2F -> *标识符字符* → [*标识符头(Head)*](../chapter3/02_Lexical_Structure.html#identifier_head) -> *标识符字符集* → [*标识符字符*](../chapter3/02_Lexical_Structure.html#identifier_character) [*标识符字符集*](../chapter3/02_Lexical_Structure.html#identifier_characters) _可选_ +> *标识符* → [*标识符头(Head)*](../chapter3/02_Lexical_Structure.html#identifier_head) [*标识符字符集*](../chapter3/02_Lexical_Structure.html#identifier_characters) _可选_ +> *标识符* → [*标识符头(Head)*](../chapter3/02_Lexical_Structure.html#identifier_head) [*标识符字符集*](../chapter3/02_Lexical_Structure.html#identifier_characters) _可选_ +> *标识符* → [*隐式参数名*](../chapter3/02_Lexical_Structure.html#implicit_parameter_name) +> *标识符集* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) | [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) **,** [*标识符集*](../chapter3/02_Lexical_Structure.html#identifier_list) +> *标识符头(Head)* → Upper- or lowercase letter A through Z +> *标识符头(Head)* → _ +> *标识符头(Head)* → U+00A8, U+00AA, U+00AD, U+00AF, U+00B2–U+00B5, or U+00B7–U+00BA +> *标识符头(Head)* → U+00BC–U+00BE, U+00C0–U+00D6, U+00D8–U+00F6, or U+00F8–U+00FF +> *标识符头(Head)* → U+0100–U+02FF, U+0370–U+167F, U+1681–U+180D, or U+180F–U+1DBF +> *标识符头(Head)* → U+1E00–U+1FFF +> *标识符头(Head)* → U+200B–U+200D, U+202A–U+202E, U+203F–U+2040, U+2054, or U+2060–U+206F +> *标识符头(Head)* → U+2070–U+20CF, U+2100–U+218F, U+2460–U+24FF, or U+2776–U+2793 +> *标识符头(Head)* → U+2C00–U+2DFF or U+2E80–U+2FFF +> *标识符头(Head)* → U+3004–U+3007, U+3021–U+302F, U+3031–U+303F, or U+3040–U+D7FF +> *标识符头(Head)* → U+F900–U+FD3D, U+FD40–U+FDCF, U+FDF0–U+FE1F, or U+FE30–U+FE44 +> *标识符头(Head)* → U+FE47–U+FFFD +> *标识符头(Head)* → U+10000–U+1FFFD, U+20000–U+2FFFD, U+30000–U+3FFFD, or U+40000–U+4FFFD +> *标识符头(Head)* → U+50000–U+5FFFD, U+60000–U+6FFFD, U+70000–U+7FFFD, or U+80000–U+8FFFD +> *标识符头(Head)* → U+90000–U+9FFFD, U+A0000–U+AFFFD, U+B0000–U+BFFFD, or U+C0000–U+CFFFD +> *标识符头(Head)* → U+D0000–U+DFFFD or U+E0000–U+EFFFD +> *标识符字符* → 数值 0 到 9 +> *标识符字符* → U+0300–U+036F, U+1DC0–U+1DFF, U+20D0–U+20FF, or U+FE20–U+FE2F +> *标识符字符* → [*标识符头(Head)*](../chapter3/02_Lexical_Structure.html#identifier_head) +> *标识符字符集* → [*标识符字符*](../chapter3/02_Lexical_Structure.html#identifier_character) [*标识符字符集*](../chapter3/02_Lexical_Structure.html#identifier_characters) _可选_ > *隐式参数名* → **$** [*十进制数字集*](../chapter3/02_Lexical_Structure.html#decimal_digits) -> 字面量语法 +> 字面量语法 > -> *字面量* → [*数值型字面量*](../chapter3/02_Lexical_Structure.html#integer_literal) | [*字符串字面量*](../chapter3/02_Lexical_Structure.html#floating_point_literal) | [*布尔字面量*](../chapter3/02_Lexical_Structure.html#string_literal) | [*空字面量*](TODO) -> *数值型字面量* → **-** _可选_ [*整形字面量*](TODO) | **-** _可选_ [*浮点型字面量*](TODO) -> *布尔字面量* → **true** | **false** -> *空字面量* → **nil** +> *字面量* → [*数值型字面量*](../chapter3/02_Lexical_Structure.html#integer_literal) | [*字符串字面量*](../chapter3/02_Lexical_Structure.html#floating_point_literal) | [*布尔字面量*](../chapter3/02_Lexical_Structure.html#string_literal) | [*空字面量*](TODO) +> *数值型字面量* → **-** _可选_ [*整形字面量*](TODO) | **-** _可选_ [*浮点型字面量*](TODO) +> *布尔字面量* → **true** | **false** +> *空字面量* → **nil** -> 整型字面量语法 +> 整型字面量语法 > -> *整型字面量* → [*二进制字面量*](../chapter3/02_Lexical_Structure.html#binary_literal) -> *整型字面量* → [*八进制字面量*](../chapter3/02_Lexical_Structure.html#octal_literal) -> *整型字面量* → [*十进制字面量*](../chapter3/02_Lexical_Structure.html#decimal_literal) -> *整型字面量* → [*十六进制字面量*](../chapter3/02_Lexical_Structure.html#hexadecimal_literal) -> *二进制字面量* → **0b** [*二进制数字*](../chapter3/02_Lexical_Structure.html#binary_digit) [*二进制字面量字符集*](../chapter3/02_Lexical_Structure.html#binary_literal_characters) _可选_ -> *二进制数字* → 数值 0 到 1 -> *二进制字面量字符* → [*二进制数字*](../chapter3/02_Lexical_Structure.html#binary_digit) | **_** -> *二进制字面量字符集* → [*二进制字面量字符*](../chapter3/02_Lexical_Structure.html#binary_literal_character) [*二进制字面量字符集*](../chapter3/02_Lexical_Structure.html#binary_literal_characters) _可选_ -> *八进制字面量* → **0o** [*八进制数字*](../chapter3/02_Lexical_Structure.html#octal_digit) [*八进制字符集*](../chapter3/02_Lexical_Structure.html#octal_literal_characters) _可选_ -> *八进字数字* → 数值 0 到 7 -> *八进制字符* → [*八进制数字*](../chapter3/02_Lexical_Structure.html#octal_digit) | **_** -> *八进制字符集* → [*八进制字符*](../chapter3/02_Lexical_Structure.html#octal_literal_character) [*八进制字符集*](../chapter3/02_Lexical_Structure.html#octal_literal_characters) _可选_ -> *十进制字面量* → [*十进制数字*](../chapter3/02_Lexical_Structure.html#decimal_digit) [*十进制字符集*](../chapter3/02_Lexical_Structure.html#decimal_literal_characters) _可选_ -> *十进制数字* → 数值 0 到 9 -> *十进制数字集* → [*十进制数字*](../chapter3/02_Lexical_Structure.html#decimal_digit) [*十进制数字集*](../chapter3/02_Lexical_Structure.html#decimal_digits) _可选_ -> *十进制字面量字符* → [*十进制数字*](../chapter3/02_Lexical_Structure.html#decimal_digit) | **_** -> *十进制字面量字符集* → [*十进制字面量字符*](../chapter3/02_Lexical_Structure.html#decimal_literal_character) [*十进制字面量字符集*](../chapter3/02_Lexical_Structure.html#decimal_literal_characters) _可选_ -> *十六进制字面量* → **0x** [*十六进制数字*](../chapter3/02_Lexical_Structure.html#hexadecimal_digit) [*十六进制字面量字符集*](../chapter3/02_Lexical_Structure.html#hexadecimal_literal_characters) _可选_ -> *十六进制数字* → 数值 0 到 9, a through f, or A through F -> *十六进制字符* → [*十六进制数字*](../chapter3/02_Lexical_Structure.html#hexadecimal_digit) | **_** -> *十六进制字面量字符集* → [*十六进制字符*](../chapter3/02_Lexical_Structure.html#hexadecimal_literal_character) [*十六进制字面量字符集*](../chapter3/02_Lexical_Structure.html#hexadecimal_literal_characters) _可选_ +> *整型字面量* → [*二进制字面量*](../chapter3/02_Lexical_Structure.html#binary_literal) +> *整型字面量* → [*八进制字面量*](../chapter3/02_Lexical_Structure.html#octal_literal) +> *整型字面量* → [*十进制字面量*](../chapter3/02_Lexical_Structure.html#decimal_literal) +> *整型字面量* → [*十六进制字面量*](../chapter3/02_Lexical_Structure.html#hexadecimal_literal) +> *二进制字面量* → **0b** [*二进制数字*](../chapter3/02_Lexical_Structure.html#binary_digit) [*二进制字面量字符集*](../chapter3/02_Lexical_Structure.html#binary_literal_characters) _可选_ +> *二进制数字* → 数值 0 到 1 +> *二进制字面量字符* → [*二进制数字*](../chapter3/02_Lexical_Structure.html#binary_digit) | **_** +> *二进制字面量字符集* → [*二进制字面量字符*](../chapter3/02_Lexical_Structure.html#binary_literal_character) [*二进制字面量字符集*](../chapter3/02_Lexical_Structure.html#binary_literal_characters) _可选_ +> *八进制字面量* → **0o** [*八进制数字*](../chapter3/02_Lexical_Structure.html#octal_digit) [*八进制字符集*](../chapter3/02_Lexical_Structure.html#octal_literal_characters) _可选_ +> *八进字数字* → 数值 0 到 7 +> *八进制字符* → [*八进制数字*](../chapter3/02_Lexical_Structure.html#octal_digit) | **_** +> *八进制字符集* → [*八进制字符*](../chapter3/02_Lexical_Structure.html#octal_literal_character) [*八进制字符集*](../chapter3/02_Lexical_Structure.html#octal_literal_characters) _可选_ +> *十进制字面量* → [*十进制数字*](../chapter3/02_Lexical_Structure.html#decimal_digit) [*十进制字符集*](../chapter3/02_Lexical_Structure.html#decimal_literal_characters) _可选_ +> *十进制数字* → 数值 0 到 9 +> *十进制数字集* → [*十进制数字*](../chapter3/02_Lexical_Structure.html#decimal_digit) [*十进制数字集*](../chapter3/02_Lexical_Structure.html#decimal_digits) _可选_ +> *十进制字面量字符* → [*十进制数字*](../chapter3/02_Lexical_Structure.html#decimal_digit) | **_** +> *十进制字面量字符集* → [*十进制字面量字符*](../chapter3/02_Lexical_Structure.html#decimal_literal_character) [*十进制字面量字符集*](../chapter3/02_Lexical_Structure.html#decimal_literal_characters) _可选_ +> *十六进制字面量* → **0x** [*十六进制数字*](../chapter3/02_Lexical_Structure.html#hexadecimal_digit) [*十六进制字面量字符集*](../chapter3/02_Lexical_Structure.html#hexadecimal_literal_characters) _可选_ +> *十六进制数字* → 数值 0 到 9, a through f, or A through F +> *十六进制字符* → [*十六进制数字*](../chapter3/02_Lexical_Structure.html#hexadecimal_digit) | **_** +> *十六进制字面量字符集* → [*十六进制字符*](../chapter3/02_Lexical_Structure.html#hexadecimal_literal_character) [*十六进制字面量字符集*](../chapter3/02_Lexical_Structure.html#hexadecimal_literal_characters) _可选_ -> 浮点型字面量语法 +> 浮点型字面量语法 > -> *浮点数字面量* → [*十进制字面量*](../chapter3/02_Lexical_Structure.html#decimal_literal) [*十进制分数*](../chapter3/02_Lexical_Structure.html#decimal_fraction) _可选_ [*十进制指数*](../chapter3/02_Lexical_Structure.html#decimal_exponent) _可选_ -> *浮点数字面量* → [*十六进制字面量*](../chapter3/02_Lexical_Structure.html#hexadecimal_literal) [*十六进制分数*](../chapter3/02_Lexical_Structure.html#hexadecimal_fraction) _可选_ [*十六进制指数*](../chapter3/02_Lexical_Structure.html#hexadecimal_exponent) -> *十进制分数* → **.** [*十进制字面量*](../chapter3/02_Lexical_Structure.html#decimal_literal) -> *十进制指数* → [*浮点数 e*](../chapter3/02_Lexical_Structure.html#floating_point_e) [*正负号*](../chapter3/02_Lexical_Structure.html#sign) _可选_ [*十进制字面量*](../chapter3/02_Lexical_Structure.html#decimal_literal) +> *浮点数字面量* → [*十进制字面量*](../chapter3/02_Lexical_Structure.html#decimal_literal) [*十进制分数*](../chapter3/02_Lexical_Structure.html#decimal_fraction) _可选_ [*十进制指数*](../chapter3/02_Lexical_Structure.html#decimal_exponent) _可选_ +> *浮点数字面量* → [*十六进制字面量*](../chapter3/02_Lexical_Structure.html#hexadecimal_literal) [*十六进制分数*](../chapter3/02_Lexical_Structure.html#hexadecimal_fraction) _可选_ [*十六进制指数*](../chapter3/02_Lexical_Structure.html#hexadecimal_exponent) +> *十进制分数* → **.** [*十进制字面量*](../chapter3/02_Lexical_Structure.html#decimal_literal) +> *十进制指数* → [*浮点数 e*](../chapter3/02_Lexical_Structure.html#floating_point_e) [*正负号*](../chapter3/02_Lexical_Structure.html#sign) _可选_ [*十进制字面量*](../chapter3/02_Lexical_Structure.html#decimal_literal) > *十六进制分数* → **.** [*十六进制数*](../chapter3/02_Lexical_Structure.html#hexadecimal_literal) - [*十六进制字面量字符集*](TODO)_可选_ -> *十六进制指数* → [*浮点数 p*](../chapter3/02_Lexical_Structure.html#floating_point_p) [*正负号*](../chapter3/02_Lexical_Structure.html#sign) _可选_ [*十六进制字面量*](../chapter3/02_Lexical_Structure.html#hexadecimal_literal) -> *浮点数 e* → **e** | **E** -> *浮点数 p* → **p** | **P** -> *正负号* → **+** | **-** + [*十六进制字面量字符集*](TODO)_可选_ +> *十六进制指数* → [*浮点数 p*](../chapter3/02_Lexical_Structure.html#floating_point_p) [*正负号*](../chapter3/02_Lexical_Structure.html#sign) _可选_ [*十六进制字面量*](../chapter3/02_Lexical_Structure.html#hexadecimal_literal) +> *浮点数 e* → **e** | **E** +> *浮点数 p* → **p** | **P** +> *正负号* → **+** | **-** -> 字符串型字面量语法 +> 字符串型字面量语法 > -> *字符串字面量* → **"** [*引用文本*](../chapter3/02_Lexical_Structure.html#quoted_text) **"** -> *引用文本* → [*引用文本条目*](../chapter3/02_Lexical_Structure.html#quoted_text_item) [*引用文本*](../chapter3/02_Lexical_Structure.html#quoted_text) _可选_ -> *引用文本条目* → [*转义字符*](../chapter3/02_Lexical_Structure.html#escaped_character) -> *引用文本条目* → **(** [*表达式*](../chapter3/04_Expressions.html#expression) **)** -> *引用文本条目* → 除了"­, \­, U+000A, or U+000D 的所有 Unicode 的字符 -> *转义字符* → **/0** | **\\** | **\t** | **\n** | **\r** | **\"** | **\'** -> *转义字符* → **\u** **{** [*十六进制标量数字集*](TODO) **}** -> *unicode 标量数字集* → Between one and eight hexadecimal digits +> *字符串字面量* → **"** [*引用文本*](../chapter3/02_Lexical_Structure.html#quoted_text) **"** +> *引用文本* → [*引用文本条目*](../chapter3/02_Lexical_Structure.html#quoted_text_item) [*引用文本*](../chapter3/02_Lexical_Structure.html#quoted_text) _可选_ +> *引用文本条目* → [*转义字符*](../chapter3/02_Lexical_Structure.html#escaped_character) +> *引用文本条目* → **(** [*表达式*](../chapter3/04_Expressions.html#expression) **)** +> *引用文本条目* → 除了"­, \­, U+000A, or U+000D 的所有 Unicode 的字符 +> *转义字符* → **/0** | **\\** | **\t** | **\n** | **\r** | **\"** | **\'** +> *转义字符* → **\u** **{** [*十六进制标量数字集*](TODO) **}** +> *unicode 标量数字集* → Between one and eight hexadecimal digits -> 运算符语法语法 +> 运算符语法语法 > -> *运算符* → [*运算符头*](../chapter3/02_Lexical_Structure.html#operator_character) [*运算符字符集*](../chapter3/02_Lexical_Structure.html#operator) _可选_ -> *运算符* → [*点运算符头*](TODO) [*点运算符字符集*](TODO) _可选_ -> *运算符字符* → **/** | **=** | **-** | **+** | **!** | ***** | **%** | **<** | **>** | **&** | **|** | **^** | **~** | **?** -> *运算符头* → U+00A1–U+00A7 -> *运算符头* → U+00A9 or U+00AB -> *运算符头* → U+00AC or U+00AE -> *运算符头* → U+00B0–U+00B1, U+00B6, U+00BB, U+00BF, U+00D7, or U+00F7 -> *运算符头* → U+2016–U+2017 or U+2020–U+2027 -> *运算符头* → U+2030–U+203E -> *运算符头* → U+2041–U+2053 -> *运算符头* → U+2055–U+205E -> *运算符头* → U+2190–U+23FF -> *运算符头* → U+2500–U+2775 -> *运算符头* → U+2794–U+2BFF -> *运算符头* → U+2E00–U+2E7F -> *运算符头* → U+3001–U+3003 -> *运算符头* → U+3008–U+3030 -> *运算符字符* → [*运算符头*](TODO) -> *运算符字符* → U+0300–U+036F -> *运算符字符* → U+1DC0–U+1DFF -> *运算符字符* → U+20D0–U+20FF -> *运算符字符* → U+FE00–U+FE0F -> *运算符字符* → U+FE20–U+FE2F -> *运算符字符* → U+E0100–U+E01EF -> *运算符字符集* → [*运算符字符*](TODO) [*运算符字符集*](TODO)_可选_ -> *点运算符头* → **..** -> *点运算符字符* → **.** | [*运算符字符*](TODO) -> *点运算符字符集* → [*点运算符字符*](TODO) [*点运算符字符集*](TODO) _可选_ -> *二元运算符* → [*运算符*](../chapter3/02_Lexical_Structure.html#operator) -> *前置运算符* → [*运算符*](../chapter3/02_Lexical_Structure.html#operator) -> *后置运算符* → [*运算符*](../chapter3/02_Lexical_Structure.html#operator) +> *运算符* → [*运算符头*](../chapter3/02_Lexical_Structure.html#operator_character) [*运算符字符集*](../chapter3/02_Lexical_Structure.html#operator) _可选_ +> *运算符* → [*点运算符头*](TODO) [*点运算符字符集*](TODO) _可选_ +> *运算符字符* → **/** | **=** | **-** | **+** | **!** | ***** | **%** | **<** | **>** | **&** | **|** | **^** | **~** | **?** +> *运算符头* → U+00A1–U+00A7 +> *运算符头* → U+00A9 or U+00AB +> *运算符头* → U+00AC or U+00AE +> *运算符头* → U+00B0–U+00B1, U+00B6, U+00BB, U+00BF, U+00D7, or U+00F7 +> *运算符头* → U+2016–U+2017 or U+2020–U+2027 +> *运算符头* → U+2030–U+203E +> *运算符头* → U+2041–U+2053 +> *运算符头* → U+2055–U+205E +> *运算符头* → U+2190–U+23FF +> *运算符头* → U+2500–U+2775 +> *运算符头* → U+2794–U+2BFF +> *运算符头* → U+2E00–U+2E7F +> *运算符头* → U+3001–U+3003 +> *运算符头* → U+3008–U+3030 +> *运算符字符* → [*运算符头*](TODO) +> *运算符字符* → U+0300–U+036F +> *运算符字符* → U+1DC0–U+1DFF +> *运算符字符* → U+20D0–U+20FF +> *运算符字符* → U+FE00–U+FE0F +> *运算符字符* → U+FE20–U+FE2F +> *运算符字符* → U+E0100–U+E01EF +> *运算符字符集* → [*运算符字符*](TODO) [*运算符字符集*](TODO)_可选_ +> *点运算符头* → **..** +> *点运算符字符* → **.** | [*运算符字符*](TODO) +> *点运算符字符集* → [*点运算符字符*](TODO) [*点运算符字符集*](TODO) _可选_ +> *二元运算符* → [*运算符*](../chapter3/02_Lexical_Structure.html#operator) +> *前置运算符* → [*运算符*](../chapter3/02_Lexical_Structure.html#operator) +> *后置运算符* → [*运算符*](../chapter3/02_Lexical_Structure.html#operator) ## 类型 -> 类型语法 +> 类型语法 > > *类型* → [*数组类型*](../chapter3/03_Types.html#array_type) | [*字典类型*](TODO) | [*函数类型*](../chapter3/03_Types.html#function_type) | [*类型标识符*](../chapter3/03_Types.html#type_identifier) | [*元组类型*](../chapter3/03_Types.html#tuple_type) | [*可选类型*](../chapter3/03_Types.html#optional_type) | [*隐式解析可选类型*](../chapter3/03_Types.html#implicitly_unwrapped_optional_type) | [*协议合成类型*](../chapter3/03_Types.html#protocol_composition_type) | [*元型类型*](../chapter3/03_Types.html#metatype_type) -> 类型注解语法 +> 类型注解语法 > > *类型注解* → **:** [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ [*类型*](../chapter3/03_Types.html#type) -> 类型标识语法 +> 类型标识语法 > -> *类型标识* → [*类型名称*](../chapter3/03_Types.html#type_name) [*泛型参数从句*](GenericParametersAndArguments.html#generic_argument_clause) _可选_ | [*类型名称*](../chapter3/03_Types.html#type_name) [*泛型参数从句*](GenericParametersAndArguments.html#generic_argument_clause) _可选_ **.** [*类型标识符*](../chapter3/03_Types.html#type_identifier) +> *类型标识* → [*类型名称*](../chapter3/03_Types.html#type_name) [*泛型参数从句*](GenericParametersAndArguments.html#generic_argument_clause) _可选_ | [*类型名称*](../chapter3/03_Types.html#type_name) [*泛型参数从句*](GenericParametersAndArguments.html#generic_argument_clause) _可选_ **.** [*类型标识符*](../chapter3/03_Types.html#type_identifier) > *类型名* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) -> 元组类型语法 +> 元组类型语法 > -> *元组类型* → **(** [*元组类型主体*](../chapter3/03_Types.html#tuple_type_body) _可选_ **)** -> *元组类型主体* → [*元组类型的元素集*](../chapter3/03_Types.html#tuple_type_element_list) **...** _可选_ -> *元组类型的元素集* → [*元组类型的元素*](../chapter3/03_Types.html#tuple_type_element) | [*元组类型的元素*](../chapter3/03_Types.html#tuple_type_element) **,** [*元组类型的元素集*](../chapter3/03_Types.html#tuple_type_element_list) -> *元组类型的元素* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ **inout** _可选_ [*类型*](../chapter3/03_Types.html#type) | **inout** _可选_ [*元素名*](../chapter3/03_Types.html#element_name) [*类型注解*](../chapter3/03_Types.html#type_annotation) +> *元组类型* → **(** [*元组类型主体*](../chapter3/03_Types.html#tuple_type_body) _可选_ **)** +> *元组类型主体* → [*元组类型的元素集*](../chapter3/03_Types.html#tuple_type_element_list) **...** _可选_ +> *元组类型的元素集* → [*元组类型的元素*](../chapter3/03_Types.html#tuple_type_element) | [*元组类型的元素*](../chapter3/03_Types.html#tuple_type_element) **,** [*元组类型的元素集*](../chapter3/03_Types.html#tuple_type_element_list) +> *元组类型的元素* → [*属性(Attributes)集*](../chapter3/06_Attributes.html#attributes) _可选_ **inout** _可选_ [*类型*](../chapter3/03_Types.html#type) | **inout** _可选_ [*元素名*](../chapter3/03_Types.html#element_name) [*类型注解*](../chapter3/03_Types.html#type_annotation) > *元素名* → [*标识符*](../chapter3/02_Lexical_Structure.html#identifier) -> 函数类型语法 +> 函数类型语法 > -> *函数类型* → [*类型*](../chapter3/03_Types.html#type) **throws** _可选_ **->** [*类型*](../chapter3/03_Types.html#type) -> *函数类型* → [*类型*](TODO) **rethrows** **->** [*类型*](TODO) +> *函数类型* → [*类型*](../chapter3/03_Types.html#type) **throws** _可选_ **->** [*类型*](../chapter3/03_Types.html#type) +> *函数类型* → [*类型*](TODO) **rethrows** **->** [*类型*](TODO) -> 数组类型语法 +> 数组类型语法 > > *数组类型* → **[** [*类型*](../chapter3/03_Types.html#array_type) **]** -> 字典类型语法 +> 字典类型语法 > > *字典类型* → **[** [*类型 **:** 类型*](TODO) **]** -> 可选类型语法 +> 可选类型语法 > > *可选类型* → [*类型*](../chapter3/03_Types.html#type) **?** -> 隐式解析可选类型(Implicitly Unwrapped Optional Type)语法 +> 隐式解析可选类型(Implicitly Unwrapped Optional Type)语法 > > *隐式解析可选类型* → [*类型*](../chapter3/03_Types.html#type) **!** -> 协议合成类型语法 +> 协议合成类型语法 > -> *协议合成类型* → **protocol** **<** [*协议标识符集*](../chapter3/03_Types.html#protocol_identifier_list) _可选_ **>** -> *协议标识符集* → [*协议标识符*](../chapter3/03_Types.html#protocol_identifier) | [*协议标识符*](../chapter3/03_Types.html#protocol_identifier) **,** [*协议标识符集*](../chapter3/03_Types.html#protocol_identifier_list) +> *协议合成类型* → **protocol** **<** [*协议标识符集*](../chapter3/03_Types.html#protocol_identifier_list) _可选_ **>** +> *协议标识符集* → [*协议标识符*](../chapter3/03_Types.html#protocol_identifier) | [*协议标识符*](../chapter3/03_Types.html#protocol_identifier) **,** [*协议标识符集*](../chapter3/03_Types.html#protocol_identifier_list) > *协议标识符* → [*类型标识符*](../chapter3/03_Types.html#type_identifier) -> 元(Metatype)类型语法 +> 元(Metatype)类型语法 > > *元类型* → [*类型*](../chapter3/03_Types.html#type) **.** **Type** | [*类型*](../chapter3/03_Types.html#type) **.** **Protocol** -> 类型继承从句语法 +> 类型继承从句语法 > -> *类型继承从句* → **:** [*类条件(class-requirement))*](TODO) **,** [*类型继承集*](../chapter3/03_Types.html#type_inheritance_list) -> *类型继承从句* → **:** [*类条件(class-requirement))*](TODO) -> *类型继承从句* → **:** [*类型继承集*](TODO) -> *类型继承集* → [*类型标识符*](../chapter3/03_Types.html#type_identifier) | [*类型标识符*](../chapter3/03_Types.html#type_identifier) **,** [*类型继承集*](../chapter3/03_Types.html#type_inheritance_list) -> *类条件* → **class** +> *类型继承从句* → **:** [*类条件(class-requirement))*](TODO) **,** [*类型继承集*](../chapter3/03_Types.html#type_inheritance_list) +> *类型继承从句* → **:** [*类条件(class-requirement))*](TODO) +> *类型继承从句* → **:** [*类型继承集*](TODO) +> *类型继承集* → [*类型标识符*](../chapter3/03_Types.html#type_identifier) | [*类型标识符*](../chapter3/03_Types.html#type_identifier) **,** [*类型继承集*](../chapter3/03_Types.html#type_inheritance_list) +> *类条件* → **class** diff --git a/source/chapter4/03_Ballons.md b/source/chapter4/03_Ballons.md index 3fa76f4b..9de551d5 100644 --- a/source/chapter4/03_Ballons.md +++ b/source/chapter4/03_Ballons.md @@ -13,4 +13,4 @@ Ballons 不但展现了 playgrounds 许多很赞的特性,还让我们看到 这个 playground 文件用到了 SpriteKit 的新特性,因此需要最新 beta 版本的 Xcode 6和 Yosemite 系统来支持它运行。 -本文由翻译自 Apple Swift Blog 的博文:[Ballons](https://developer.apple.com/swift/blog/?id=9) +本文由翻译自 Apple Swift Blog 的博文:[Ballons](https://developer.apple.com/swift/blog/?id=9) diff --git a/source/chapter4/04_Interacting_with_C_Pointers.md b/source/chapter4/04_Interacting_with_C_Pointers.md index f2a0ce68..bcc00928 100644 --- a/source/chapter4/04_Interacting_with_C_Pointers.md +++ b/source/chapter4/04_Interacting_with_C_Pointers.md @@ -2,7 +2,7 @@ ----------------- > 翻译:[老码团队翻译组-Relly](http://weibo.com/penguinliong/) -> 校对:[老码团队翻译组-Tyrion](http://weibo.com/u/5241713117) +> 校对:[老码团队翻译组-Tyrion](http://weibo.com/u/5241713117) 本页包含内容: diff --git a/source/chapter4/05_Value_and_Reference_Types.md b/source/chapter4/05_Value_and_Reference_Types.md index 81aeace3..9f3bc0a0 100644 --- a/source/chapter4/05_Value_and_Reference_Types.md +++ b/source/chapter4/05_Value_and_Reference_Types.md @@ -11,7 +11,7 @@ - [如何选择类型](#how-to-choose) ### Swift 里面的类型分为两种: - + * **值类型(Value Types)**:每个实例都保留了一分独有的数据拷贝,一般以结构体 `(struct)`、` 枚举(enum)` 或者 `元组(tuple)`的形式出现。 * **引用类型(Reference Type)**:每个实例共享同一份数据来源,一般以 `类(class)`的形式出现。 diff --git a/source/chapter4/06_Access_Control_and_Protected.md b/source/chapter4/06_Access_Control_and_Protected.md index 9a315a63..f62d00aa 100644 --- a/source/chapter4/06_Access_Control_and_Protected.md +++ b/source/chapter4/06_Access_Control_and_Protected.md @@ -8,7 +8,7 @@ 很多其他编程语言都有一种”protected“设定,可以限制某些类方法只能被它的子类所使用。 -Swift 支持了访问控制后,大家给我们的反馈都很不错。而有的开发者问我们:“为什么 Swift 没有类似 protected 的选项?” +Swift 支持了访问控制后,大家给我们的反馈都很不错。而有的开发者问我们:“为什么 Swift 没有类似 protected 的选项?” **当我们在设计 Swift 访问控制的不同等级时,我们认为有两种主要场景:** diff --git a/source/chapter4/07_Optional_Case_Study.md b/source/chapter4/07_Optional_Case_Study.md index ff8c9938..4a38ee93 100644 --- a/source/chapter4/07_Optional_Case_Study.md +++ b/source/chapter4/07_Optional_Case_Study.md @@ -63,7 +63,7 @@ extension Dictionary { ```swift var dic: Dictionary = [ "1": 2, "3":3, "4":5 ] -var t = dic.valuesForKeys(["1", "4"]) +var t = dic.valuesForKeys(["1", "4"]) //结果为:[Optional(2), Optional(5)] var t = dict.valuesForKeys(["3", "9"])