fix anchor name and link format
This commit is contained in:
@ -22,7 +22,7 @@ Swift 中存在四种表达式:前缀表达式,二元表达式,基本表
|
||||
|
||||
关于 Swift 标准库提供的运算符的更多信息,请参阅 [*Operators Declarations*](https://developer.apple.com/documentation/swift/operator_declarations)。
|
||||
|
||||
除了标准库运算符,你也可以对某个变量使用 `&` 运算符,从而将其传递给函数的输入输出参数。更多信息,请参阅 [输入输出参数](../02_language_guide/06_Functions.md#in_out_parameters)。
|
||||
除了标准库运算符,你也可以对某个变量使用 `&` 运算符,从而将其传递给函数的输入输出参数。更多信息,请参阅 [输入输出参数](../02_language_guide/06_Functions.md#in-out-parameters)。
|
||||
|
||||
> 前缀表达式语法
|
||||
>
|
||||
@ -137,7 +137,7 @@ sum = (try someThrowingFunction()) + anotherThrowingFunction() // 错误:try
|
||||
|
||||
如果条件为真,那么对第一个表达式进行求值并返回结果。否则,对第二个表达式进行求值并返回结果。未使用的表达式不会进行求值。
|
||||
|
||||
关于使用三元条件运算符的例子,请参阅 [三元条件运算符](../02_language_guide/02_Basic_Operators.md#ternary_conditional_operator)。
|
||||
关于使用三元条件运算符的例子,请参阅 [三元条件运算符](../02_language_guide/02_Basic_Operators.md#ternary-conditional-operator)。
|
||||
|
||||
> 三元条件运算符语法
|
||||
>
|
||||
@ -205,7 +205,7 @@ f(x as Any)
|
||||
>
|
||||
|
||||
#### primary-expression {#primary-expression}
|
||||
> *基本表达式* → [*标识符*](./02_Lexical_Structure.md#identifier) [*泛型实参子句*](./09_Generic_Parameters_and_Arguments.md#generic-argument-clause)<sub>可选</sub>
|
||||
> *基本表达式* → [*标识符*](./02_Lexical_Structure.md#identifier) [*泛型实参子句*](./09-Generic-Parameters-and-Arguments.md#generic-argument-clause)<sub>可选</sub>
|
||||
>
|
||||
> *基本表达式* → [*字面量表达式*](#literal-expression)
|
||||
>
|
||||
@ -330,7 +330,7 @@ Xcode 使用 playground 字面量对程序编辑器中的颜色、文件或者
|
||||
> *playground 字面量* → **#fileLiteral ( resourceName : [*表达式*](#expression) )**
|
||||
>
|
||||
>
|
||||
#### playground 字面量* → **#imageLiteral ( resourceName : [*表达式*](#expression) )**self_expression {#self-expression}
|
||||
#### playground 字面量* → **#imageLiteral ( resourceName : [*表达式*](#expression) )**self-expression {#self-expression}
|
||||
>
|
||||
|
||||
### Self 表达式
|
||||
@ -434,7 +434,7 @@ struct Point {
|
||||
}
|
||||
```
|
||||
|
||||
闭包的参数声明形式跟函数一样,请参阅 [函数声明](./06_Declarations.md#function_declaration)。
|
||||
闭包的参数声明形式跟函数一样,请参阅 [函数声明](./06_Declarations.md#function-declaration)。
|
||||
|
||||
闭包还有几种特殊的形式,能让闭包使用起来更加简洁:
|
||||
|
||||
@ -460,11 +460,11 @@ myFunction { return $0 + $1 }
|
||||
myFunction { $0 + $1 }
|
||||
```
|
||||
|
||||
关于如何将闭包作为参数来传递的内容,请参阅 [函数调用表达式](#function_call_expression)。
|
||||
关于如何将闭包作为参数来传递的内容,请参阅 [函数调用表达式](#function-call-expression)。
|
||||
|
||||
使用闭包表达式时,可以不必将其存储在一个变量或常量中,例如作为函数调用的一部分来立即使用一个闭包。在上面的例子中,传入 `myFunction` 的闭包表达式就是这种立即使用类型的闭包。因此,一个闭包是否逃逸与其使用时的上下文相关。一个会被立即调用或者作为函数的非逃逸参数传递的闭包表达式是非逃逸的,否则,这个闭包表达式是逃逸的。
|
||||
|
||||
关于逃逸闭包的内容,请参阅 [逃逸闭包](./02_language_guide/07_Closures.md#escaping_closures)。
|
||||
关于逃逸闭包的内容,请参阅 [逃逸闭包](./02_language_guide/07_Closures.md#escaping-closures)。
|
||||
|
||||
## 捕获列表 {#capture-lists}
|
||||
默认情况下,闭包会捕获附近作用域中的常量和变量,并使用强引用指向它们。你可以通过一个*捕获列表*来显式指定它的捕获行为。
|
||||
@ -522,7 +522,7 @@ myFunction { [unowned self] in print(self.title) } // 无主引用捕获
|
||||
myFunction { [weak parent = self.parent] in print(parent!.title) }
|
||||
```
|
||||
|
||||
关于闭包表达式的更多信息和例子,请参阅 [闭包表达式](../02_language_guide/07_Closures.md#closure_expressions)。关于捕获列表的更多信息和例子,请参阅 [解决闭包引起的循环强引用](../02_language_guide/24_Automatic_Reference_Counting.md#resolving_strong_reference_cycles_for_closures)。
|
||||
关于闭包表达式的更多信息和例子,请参阅 [闭包表达式](../02_language_guide/07_Closures.md#closure-expressions)。关于捕获列表的更多信息和例子,请参阅 [解决闭包引起的循环强引用](../02-language-guide/24-Automatic-Reference-Counting.md#resolving-strong-reference-cycles-for-closures)。
|
||||
|
||||
> 闭包表达式语法
|
||||
>
|
||||
@ -537,13 +537,13 @@ myFunction { [weak parent = self.parent] in print(parent!.title) }
|
||||
#### closure-signature {#closure-signature}
|
||||
>
|
||||
>
|
||||
> 闭包签名* → [*参数子句*](#parameter-clause) [*函数结果*](05_Declarations.md#function-result)<sub>可选</sub> **in**
|
||||
> 闭包签名* → [*参数子句*](#parameter-clause) [*函数结果*](05-Declarations.md#function-result)<sub>可选</sub> **in**
|
||||
>
|
||||
> *闭包签名* → [*标识符列表*](#identifier-list) [*函数结果*](05_Declarations.md#function-result)<sub>可选</sub> **in**
|
||||
> *闭包签名* → [*标识符列表*](#identifier-list) [*函数结果*](05-Declarations.md#function-result)<sub>可选</sub> **in**
|
||||
>
|
||||
> *闭包签名* → [*捕获列表*](#capture-list) [*参数子句*](05_Declarations.md#parameter-clause) [*函数结果*](./06_Declarations.md#function-result)<sub>可选</sub> **in**
|
||||
> *闭包签名* → [*捕获列表*](#capture-list) [*参数子句*](05-Declarations.md#parameter-clause) [*函数结果*](./06-Declarations.md#function-result)<sub>可选</sub> **in**
|
||||
>
|
||||
> *闭包签名* → [*捕获列表*](#capture-list) [*标识符列表*](02_Lexical_Structure.md#identifier-list) [*函数结果*](./06_Declarations.md#function-result)<sub>可选</sub> **in**
|
||||
> *闭包签名* → [*捕获列表*](#capture-list) [*标识符列表*](02-Lexical-Structure.md#identifier-list) [*函数结果*](./06-Declarations.md#function-result)<sub>可选</sub> **in**
|
||||
>
|
||||
> *闭包签名* → [*捕获列表*](#capture-list) **in**
|
||||
>
|
||||
@ -772,7 +772,7 @@ print(interestingNumbers[keyPath: \[String: [Int]].["hexagonal"]!.count.bitWidth
|
||||
// 打印 "64"
|
||||
```
|
||||
|
||||
关于更多如何使用 key path 与 Objective-C APIs 交互的信息,请参阅 [在 Swift 中使用 Objective-C 运行时特性](https://developer.apple.com/documentation/swift/using_objective_c_runtime_features_in_swift)。关于更多 key-value 编程和 key-value 观察的信息,请参阅 [Key-Value 编程](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/KeyValueCoding/index.html#//apple_ref/doc/uid/10000107i) 和 [Key-Value 观察编程](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html#//apple_ref/doc/uid/10000177i)。
|
||||
关于更多如何使用 key path 与 Objective-C APIs 交互的信息,请参阅 [在 Swift 中使用 Objective-C 运行时特性](https://developer.apple.com/documentation/swift/using_objective_c_runtime_features_in_swift)。关于更多 key-value 编程和 key-value 观察的信息,请参阅 [Key-Value 编程](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/KeyValueCoding/index.html#//apple-ref/doc/uid/10000107i) 和 [Key-Value 观察编程](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html#//apple-ref/doc/uid/10000177i)。
|
||||
|
||||
> key-path 表达式语法
|
||||
>
|
||||
@ -823,7 +823,7 @@ class SomeClass: NSObject {
|
||||
self.property = property
|
||||
}
|
||||
}
|
||||
let selectorForMethod = #selector(SomeClass.doSomething(_:))
|
||||
let selectorForMethod = #selector(SomeClass.doSomething(-:))
|
||||
let selectorForPropertyGetter = #selector(getter: SomeClass.property)
|
||||
```
|
||||
|
||||
@ -836,7 +836,7 @@ extension SomeClass {
|
||||
@objc(doSomethingWithString:)
|
||||
func doSomething(_ x: String) { }
|
||||
}
|
||||
let anotherSelector = #selector(SomeClass.doSomething(_:) as (SomeClass) -> (String) -> Void)
|
||||
let anotherSelector = #selector(SomeClass.doSomething(-:) as (SomeClass) -> (String) -> Void)
|
||||
```
|
||||
|
||||
由于选择器是在编译时创建的,因此编译器可以检查方法或者属性是否存在,以及是否在运行时暴露给了 Objective-C 。
|
||||
@ -852,11 +852,11 @@ let anotherSelector = #selector(SomeClass.doSomething(_:) as (SomeClass) -> (Str
|
||||
>
|
||||
|
||||
#### selector-expression {#selector-expression}
|
||||
> *选择器表达式* → __#selector__ **(** [*表达式*](#expression) **)**
|
||||
> *选择器表达式* → __#selector-- **(** [*表达式*](#expression) **)**
|
||||
>
|
||||
> *选择器表达式* → __#selector__ **(** [*getter:表达式*](#expression) **)**
|
||||
> *选择器表达式* → __#selector-- **(** [*getter:表达式*](#expression) **)**
|
||||
>
|
||||
> *选择器表达式* → __#selector__ **(** [*setter:表达式*](#expression) **)**
|
||||
> *选择器表达式* → __#selector-- **(** [*setter:表达式*](#expression) **)**
|
||||
>
|
||||
|
||||
## Key-path 字符串表达式 {#key-path-string-expressions}
|
||||
@ -899,7 +899,7 @@ print(keyPath == c.getSomeKeyPath())
|
||||
|
||||
由于 key-path 字符串表达式在编译期才创建,编译期可以检查属性是否存在,以及属性是否暴露给 Objective-C 运行时。
|
||||
|
||||
关于更多如何使用 key path 与 Objective-C APIs 交互的信息,请参阅 [在 Swift 中使用 Objective-C 运行时特性](./https://developer.apple.com/documentation/swift/using_objective_c_runtime_features_in_swift)。关于更多 key-value 编程和 key-value 观察的信息,请参阅 [Key-Value 编程](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/KeyValueCoding/index.md#//apple_ref/doc/uid/10000107i) 和 [Key-Value 观察编程](./https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.md#//apple_ref/doc/uid/10000177i)。
|
||||
关于更多如何使用 key path 与 Objective-C APIs 交互的信息,请参阅 [在 Swift 中使用 Objective-C 运行时特性](./https://developer.apple.com/documentation/swift/using_objective_c_runtime_features_in_swift)。关于更多 key-value 编程和 key-value 观察的信息,请参阅 [Key-Value 编程](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/KeyValueCoding/index.md#//apple-ref/doc/uid/10000107i) 和 [Key-Value 观察编程](./https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.md#//apple-ref/doc/uid/10000177i)。
|
||||
|
||||
> 注意
|
||||
>
|
||||
@ -928,7 +928,7 @@ print(keyPath == c.getSomeKeyPath())
|
||||
#### postfix-expression {#postfix-expression}
|
||||
> *后缀表达式* → [*基本表达式*](#primary-expression)
|
||||
>
|
||||
> *后缀表达式* → [*后缀表达式*](#postfix-expression) [*后缀运算符*](02_Lexical_Structure.md#postfix-operator)
|
||||
> *后缀表达式* → [*后缀表达式*](#postfix-expression) [*后缀运算符*](02-Lexical-Structure.md#postfix-operator)
|
||||
>
|
||||
> *后缀表达式* → [*函数调用表达式*](#function-call-expression)
|
||||
>
|
||||
@ -999,9 +999,9 @@ myData.someMethod {$0 == 13}
|
||||
>
|
||||
#### function-call-argument {#function-call-argument}
|
||||
>
|
||||
> *函数调用参数* → [表达式](#expression) | [标识符](02_Lexical_Structure.md#identifier) **:** [*表达式*](#expression)
|
||||
> *函数调用参数* → [表达式](#expression) | [标识符](02-Lexical-Structure.md#identifier) **:** [*表达式*](#expression)
|
||||
>
|
||||
> *函数调用参数* → [运算符](./02_Lexical_Structure.md#operator) | [标识符](./02_Lexical_Structure.md#identifier) **:** [*运算符*](./02_Lexical_Structure.md#operator)
|
||||
> *函数调用参数* → [运算符](./02_Lexical_Structure.md#operator) | [标识符](./02-Lexical-Structure.md#identifier) **:** [*运算符*](./02-Lexical-Structure.md#operator)
|
||||
>
|
||||
>
|
||||
>
|
||||
@ -1116,11 +1116,11 @@ let x = [10, 3, 20, 15, 4]
|
||||
>
|
||||
|
||||
#### explicit-member-expression {#explicit-member-expression}
|
||||
> *显式成员表达式* → [*后缀表达式*](#postfix-expression) **.** [*十进制数字*] (02_Lexical_Structure.md#decimal-digit)
|
||||
> *显式成员表达式* → [*后缀表达式*](#postfix-expression) **.** [*十进制数字*] (02-Lexical-Structure.md#decimal-digit)
|
||||
>
|
||||
> *显式成员表达式* → [*后缀表达式*](#postfix-expression) **.** [*标识符*](02_Lexical_Structure.md#identifier) [*泛型实参子句*](./09_Generic_Parameters_and_Arguments.md#generic-argument-clause)<sub>可选</sub><br/>
|
||||
> *显式成员表达式* → [*后缀表达式*](#postfix-expression) **.** [*标识符*](02-Lexical-Structure.md#identifier) [*泛型实参子句*](./09-Generic-Parameters-and-Arguments.md#generic-argument-clause)<sub>可选</sub><br/>
|
||||
>
|
||||
> *显式成员表达式* → [*后缀表达式*](#postfix-expression) **.** [*标识符*] (02_Lexical_Structure.md#identifier) **(** [*参数名称*](#argument-names) **)**
|
||||
> *显式成员表达式* → [*后缀表达式*](#postfix-expression) **.** [*标识符*] (02-Lexical-Structure.md#identifier) **(** [*参数名称*](#argument-names) **)**
|
||||
>
|
||||
|
||||
#### argument-names {#argument-names}
|
||||
@ -1159,7 +1159,7 @@ let x = [10, 3, 20, 15, 4]
|
||||
|
||||
要获取下标表达式的值,可将索引表达式作为下标表达式的参数来调用下标 getter。下标 setter 的调用方式与之一样。
|
||||
|
||||
关于下标的声明,请参阅 [协议下标声明](./06_Declarations.md#protocol_subscript_declaration)。
|
||||
关于下标的声明,请参阅 [协议下标声明](./06_Declarations.md#protocol-subscript-declaration)。
|
||||
|
||||
> 下标表达式语法
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user