diff --git a/source/chapter2/02_Basic_Operators.md b/source/chapter2/02_Basic_Operators.md
index 39ac015f..5ca9929f 100644
--- a/source/chapter2/02_Basic_Operators.md
+++ b/source/chapter2/02_Basic_Operators.md
@@ -1,30 +1,30 @@
# 基本运算符
-运算符是检查, 改变, 合并值的特殊符号或短语. 例如, 加号 `+` 把计算两个数的和(如 `let i = 1 + 2`). 复杂些的运行算包括逻辑与`&&`(如 `if enteredDoorCode && passedRetinaScan`), 还有自增运算符 `++i` 这样让自身加一的便捷运算.
+运算符是检查,改变,合并值的特殊符号或短语。例如,加号`+`把计算两个数的和(如 `let i = 1 + 2`)。复杂些的运行算包括逻辑与`&&`(如 `if enteredDoorCode && passedRetinaScan`),还有自增运算符`++i`这样让自身加一的便捷运算。
-Swift支持大部分标准C语言的运算符, 且改进许多特性来减少常规编码错误. 如, 赋值符 `=` 不返回值, 以防止错把等号 `==` 写成赋值号 `=` 而导致Bug. 数值运算符( `+` , `-`, `*`, `/`, `%`等)会检测并不允许值溢出, 以此来避免保存变量时由于变量大于或小于其类型所能承载的范围时导致的异常结果. 当然允许你选择使用Swift的溢出运算符来玩溢出. 具体使用请移步[溢出运算符](Overflow Operators).
+Swift支持大部分标准C语言的运算符,且改进许多特性来减少常规编码错误。如,赋值符`=`不返回值,以防止错把等号`==`写成赋值号`=`而导致Bug。数值运算符(`+`,`-`,`*`,`/`,`%`等)会检测并不允许值溢出,以此来避免保存变量时由于变量大于或小于其类型所能承载的范围时导致的异常结果。当然允许你选择使用Swift的溢出运算符来玩溢出。具体使用请移步[溢出运算符](Overflow Operators)。
-区别于C语言, 在Swift中你可以对浮点数进行取余运算( `%` ), 还提供了C语言没有的表达两数之间的值的区间运算符, ( `a..b` 和 `a...b` ), 这方便我们表达一个区间内的数值.
+区别于C语言,在Swift中你可以对浮点数进行取余运算(`%`),还提供了C语言没有的表达两数之间的值的区间运算符,(`a..b`和`a...b`),这方便我们表达一个区间内的数值。
-本章节只描述了Swift中的基本运算符, [高级运算符](http://#)包含了高级运算符,及如何自定义运算符, 及如何进行自定义类型的运算符重载.
+本章节只描述了Swift中的基本运算符,[高级运算符](http://#)包含了高级运算符,及如何自定义运算符,及如何进行自定义类型的运算符重载。
# 术语
-运算符有一目, 双目和三目运算符.
+运算符有一目,双目和三目运算符。
-一目运算符对单一操作对象操作, 如 `-a`.
+一目运算符对单一操作对象操作,如`-a`。
-一目运算符分前置符和后置运算符, 前置运算符需紧排操作对象之前, 如 `!b`, 后置运算符需紧跟操作对象之后,如 `i++`,
+一目运算符分前置符和后置运算符,前置运算符需紧排操作对象之前,如`!b`,后置运算符需紧跟操作对象之后,如`i++`,
-双目运算符操作两个操作对象, 如 `2 + 3`. 是中置的, 因为它们出现在两个操作对象之间.
+双目运算符操作两个操作对象,如 `2 + 3`。是中置的,因为它们出现在两个操作对象之间。
-三目运算符操作三个操作对象, 和C语言一样, Swift只有一个三目运算符, 就是三目条件运算符 `a ? b : c`.
+三目运算符操作三个操作对象,和C语言一样,Swift只有一个三目运算符,就是三目条件运算符 `a?b:c`。
-受运算符影响的值叫操作数, 在表达式 `1 + 2` 中, 加号 `+` 是双目运算符, 它的两个操作数是值 `1` 和 `2`.
+受运算符影响的值叫操作数,在表达式 `1 + 2` 中,加号`+`是双目运算符,它的两个操作数是值`1`和`2`。
# 赋值运算符
-赋值运算 `a = b`, 表示用 `b` 的值来初始化或更新 `a` 的值.
+赋值运算 `a = b`,表示用`b`的值来初始化或更新`a`的值。
```swift
let b = 10
@@ -33,12 +33,12 @@ a = b
// a 现在等于 10
```
-如果赋值的右边是一个多元组, 它的元素可以马上被分解多个变量或变量
+如果赋值的右边是一个多元组,它的元素可以马上被分解多个变量或变量
```
let (x, y) = (1, 2)
// 现在 x 等于 1, y 等于 2
```
-与C语言和Objective-C不同, Swift的赋值操作并不返回任何值. 所以以下代码是错误的:
+与C语言和Objective-C不同,Swift的赋值操作并不返回任何值。所以以下代码是错误的:
```swift
if x = y {
@@ -46,16 +46,16 @@ if x = y {
}
```
-这个特性使得你不无法把`==`错写成`=`了, 由于`if x = y`是错误代码, Swift从底层帮你避免了这些代码错误.
+这个特性使得你不无法把`==`错写成`=`了,由于`if x = y`是错误代码,Swift从底层帮你避免了这些代码错误。
# 数值运算
-Swift让所有数值类型都支持了基本的四则运算:
+Swift让所有数值类型都支持了基本的四则运算:
-- 加法 `+`
-- 减法 `-`
-- 乘法 `*`
-- 除法 `/`
+- 加法`+`
+- 减法`-`
+- 乘法`*`
+- 除法`/`
```swift
1 + 2 // 等于 3
@@ -64,15 +64,15 @@ Swift让所有数值类型都支持了基本的四则运算:
10.0 / 2.5 // 等于 4.0
```
-与C语言和Objective-C不同的是, Swift默认不允许在数值运算中出现溢出情况. 但你可以使用Swift的溢出运算符来达到你有目的的溢出, (如 `a &+ b` ). 详情请移步: [溢出运算符](Overflow Operators).
+与C语言和Objective-C不同的是,Swift默认不允许在数值运算中出现溢出情况。但你可以使用Swift的溢出运算符来达到你有目的的溢出,(如 `a &+ b`)。详情请移步:[溢出运算符](Overflow Operators)。
-加法操作 `+` 也用于字符串的拼接:
+加法操作`+`也用于字符串的拼接:
```swift
"hello, " + "world" // 等于 "hello, world"
```
-两个字符类型或一个字符类型和一个字符串类型, 相加会生成一个新的字符串类型:
+两个字符类型或一个字符类型和一个字符串类型,相加会生成一个新的字符串类型:
```swift
let dog: Character = "d"
@@ -81,19 +81,19 @@ let dogCow = dog + cow
// 译者注: 原谅的引号内是很可爱的小狗和小牛, 但win os下不支持表情字符, 所以改成了普通字符
// dogCow 现在是 "dc"
```
-详细请点击 [字符,字符串的拼接](http://#).
+详细请点击[字符,字符串的拼接](http://#)。
# 求余运算
-求余运算 `a % b` 是计算 `b` 的多少倍刚刚好可以容入 `a` , 多出来的那部分叫余数.
+求余运算 `a % b` 是计算`b`的多少倍刚刚好可以容入`a`,多出来的那部分叫余数。
> 注意
-> 求余运算(%)在其他语言也叫取模运算. 然而严格说来, 我们看该运算符对负数的操作结果, `求余` 比 `取模` 更合适些.
+> 求余运算(%)在其他语言也叫取模运算。然而严格说来,我们看该运算符对负数的操作结果,`求余` 比 `取模` 更合适些。
-我们来谈谈取余是怎么回事, 计算 `9 % 4`, 你先计算出4的多少倍会刚好可以容入 `9` 中.
+我们来谈谈取余是怎么回事,计算 `9 % 4`,你先计算出4的多少倍会刚好可以容入`9`中。
-2倍, 非常好, 那余数是1 (用'*'标出)
+2倍,非常好,那余数是1(用'*'标出)
@@ -120,64 +120,64 @@ let dogCow = dog + cow
9 % 4 // 等于 1
```
-为了得到 `a % b` 的结果, `%`计算了以下等式, 并输出`余数`作为结果:
+为了得到 `a % b` 的结果,`%`计算了以下等式,并输出`余数`作为结果:
```
a = (b × 倍数) + 余数
```
-当`倍数`取最大值的时候, 就会刚好可以容入 `a` 中.
+当`倍数`取最大值的时候,就会刚好可以容入`a`中。
-把 `9` 和 `4` 代入等式中, 我们得 `1`:
+把`9`和`4`代入等式中,我们得`1`:
```swift
9 = (4 × 2) + 1
```
-同样的方法, 我来们计算 `-9 % 4` :
+同样的方法,我来们计算 `-9 % 4`:
```
-9 % 4 // 等于 -1
```
-把 `-9` 和 `4` 代入等式, `-2` 是取到的最大整数:
+把`-9`和`4`代入等式,`-2`是取到的最大整数:
```swift
-9 = (4 × -2) + -1
```
-余数是 `-1`.
+余数是`-1`。
-在对负数 `-b` 求余时, `-b`的符号会被忽略. 这意味着 `a % b` 和 `a % -b`的结果是相同的.
+在对负数`-b`求余时,`-b`的符号会被忽略。这意味着 `a % b` 和 `a % -b`的结果是相同的。
## 浮点数求余计算
-不同于C和Objective-C, Swift中是可以对浮点数进行求余的.
+不同于C和Objective-C,Swift中是可以对浮点数进行求余的。
```swift
8 % 2.5 // 等于 0.5
```
-这个例子中, 8除于2.5等于3余0.5, 所以结果是0.5.
+这个例子中,8除于2。5等于3余0。5,所以结果是0。5。
# 自增和自增运算
-和C一样, Swift也提供了方便对变量本身加1或减1的自增 `++` 和自减 `--` 的运算符. 其操作对象可以是整形和浮点型。
+和C一样,Swift也提供了方便对变量本身加1或减1的自增`++`和自减`--`的运算符。其操作对象可以是整形和浮点型。
```
var i = 0
++i // 现在 i = 1
```
-每调用一次 `++i`, `i` 的值就会加1.
-实际上, `++i` 是 `i = i + 1` 的简写, 而 `--i` 是 `i = i - 1`的简写.
+每调用一次`++i`,`i`的值就会加1。
+实际上,`++i`是 `i = i + 1` 的简写,而`--i`是 `i = i - 1`的简写。
-`++` 和 `--`既是前置又是后置运算. `++i`, `i++`, `--i` 和 `i--` 都是有效的写法.
+`++`和`--`既是前置又是后置运算。`++i`,`i++`,`--i`和`i--`都是有效的写法。
-我们需要注意的是这些运算符修改了 `i` 后有一个返回值. 如果你只想修改 `i` 的值, 那你就可以忽略这个返回值. 但如果你想使用返回值, 你就需要留意前置和后置操作的返回值是不同的.
+我们需要注意的是这些运算符修改了`i`后有一个返回值。如果你只想修改`i`的值,那你就可以忽略这个返回值。但如果你想使用返回值,你就需要留意前置和后置操作的返回值是不同的。
-当 `++` 前置的时候, 先自増再返回.
+当`++`前置的时候,先自増再返回。
-当 `++` 后置的时候, 先返回再自增.
+当`++`后置的时候,先返回再自增。
-不懂? 我们看例子:
+不懂?我们看例子:
```swift
var a = 0
@@ -185,16 +185,16 @@ let b = ++a // a 和 b 现在都是 1
let c = a++ // a 现在 2, 但 c 是 a 自增前的值 1
```
-上述例子, `let b = ++a`, 先把 `a` 加1了再返回 `a` 的值. 所以 `a` 和 `b` 都是新值 `1`.
+上述例子,`let b = ++a`,先把`a`加1了再返回`a`的值。所以`a`和`b`都是新值`1`。
-而 `let c = a++`, 是先返回了 `a` 的值, 然后 `a` 才加1. 所以 `c` 得到了 `a` 的旧值1, 而 `a` 加1后变成2.
+而 `let c = a++`,是先返回了`a`的值,然后`a`才加1。所以`c`得到了`a`的旧值1,而`a`加1后变成2。
-除非你需要使用 `i++` 的特性, 不然推荐你使用 `++i` 和 `--i`, 因为先修改后返回这样的行为更符合我们的逻辑.
+除非你需要使用`i++`的特性,不然推荐你使用`++i`和`--i`,因为先修改后返回这样的行为更符合我们的逻辑。
# 单目负号
-数值的正负号可以使用前缀 `-` (即单目负号) 来切换:
+数值的正负号可以使用前缀`-`(即单目负号)来切换:
```swift
let three = 3
@@ -202,52 +202,52 @@ let minusThree = -three // minusThree 等于 -3
let plusThree = -minusThree // plusThree 等于 3, 或 "负负3"
```
-单目负号写在操作数之前, 中间没有空格.
+单目负号写在操作数之前,中间没有空格。
# 单目正号
-单目正号 `+` 不做任何改变地返回操作数的值.
+单目正号`+`不做任何改变地返回操作数的值。
```swift
let minusSix = -6
let alsoMinusSix = +minusSix // alsoMinusSix 等于 -6
```
-虽然单目 `+` 做无用功, 但当你在使用单目负号来表达负数时, 你可以使用单目正号来表达正数, 如此你的代码会具有对称美.
+虽然单目`+`做无用功,但当你在使用单目负号来表达负数时,你可以使用单目正号来表达正数,如此你的代码会具有对称美。
# 复合赋值
-如同强大的C语言, Swift也提供把其他运算符和赋值运算 `=` 组合的复合赋值运算符, 加赋运算 `+=` 是其中一个例子:
+如同强大的C语言,Swift也提供把其他运算符和赋值运算`=`组合的复合赋值运算符,加赋运算`+=`是其中一个例子:
```swift
var a = 1
a += 2 // a 现在是 3
```
-表达式 `a += 2` 是 `a = a + 2` 的简写, 一个加赋运算就把加法和赋值两件事完成了.
+表达式 `a += 2` 是 `a = a + 2` 的简写,一个加赋运算就把加法和赋值两件事完成了。
-> 注意:
+> 注意:
-> 复合赋值运算没有返回值, `let b = a += 2` 这类代码是错误. 这不同于上面提到的自增和自减运算符.
+> 复合赋值运算没有返回值,`let b = a += 2` 这类代码是错误。这不同于上面提到的自增和自减运算符。
-[表达式](http://#)里有复合运算符的完整列表.
+[表达式](http://#)里有复合运算符的完整列表。
# 比较运算
-所有标准C中的比较运算都可以在Swift中使用.
+所有标准C中的比较运算都可以在Swift中使用。
- 等于 `a == b`
-- 不等于 `a != b`
+- 不等于 `a!= b`
- 大于 `a > b`
- 小于 `a < b`
- 大于等于 `a >= b`
- 小于等于 `a <= b`
-> 注意:
+> 注意:
-> Swift也提供恒等 `===` 和不恒等 `!==` 这两个比较符来判断两个对象是否引用同一个对象实例. 更多细节在 [类与结构](Classes and Structures).
+> Swift也提供恒等`===`和不恒等`!==`这两个比较符来判断两个对象是否引用同一个对象实例。更多细节在[类与结构](Classes and Structures)。
-每个比较运算都返回了一个标识表达式是否成立的布尔值:
+每个比较运算都返回了一个标识表达式是否成立的布尔值:
```swift
1 == 1 // true, 因为 1 等于 1
@@ -258,7 +258,7 @@ a += 2 // a 现在是 3
2 <= 1 // false, 因为 2 并不小于等于 1
```
-比较运算多用于条件语句, 如 `if` 条件:
+比较运算多用于条件语句,如`if`条件:
```swift
let name = "world"
@@ -270,13 +270,13 @@ if name == "world" {
// 输出 "hello, world", 因为 `name` 就是等于 "world"
```
-关于 `if` 语句, 请看 [控制流](Control Flow).
+关于`if`语句,请看[控制流](Control Flow)。
# 三目条件运算
-三目条件运算的特殊在于它是有三个操作数的运算符, 它的原型是 `问题 ? 答案1 : 答案2`. 它简洁地表达根据 `问题` 成立与否作出二选一的操作. 如果 `问题` 成立, 返回 `答案1` 的结果; 如果不成立, 返回 `答案2` 的结果.
+三目条件运算的特殊在于它是有三个操作数的运算符,它的原型是 `问题?答案1:答案2`。它简洁地表达根据 `问题` 成立与否作出二选一的操作。如果 `问题` 成立,返回 `答案1` 的结果; 如果不成立,返回 `答案2` 的结果。
-使用三目条件运算简化了以下代码:
+使用三目条件运算简化了以下代码:
```swift
if question: {
@@ -287,7 +287,7 @@ else {
}
```
-这里有个计算表格行高的例子. 如果有表头, 那行高应比内容高度要高出50像素; 如果没有表头, 只需高出20像素.
+这里有个计算表格行高的例子。如果有表头,那行高应比内容高度要高出50像素; 如果没有表头,只需高出20像素。
```swift
let contentHeight = 40
@@ -296,7 +296,7 @@ let rowHeight = contentHeight + (hasHeader ? 50 : 20)
// rowHeight 现在是 90
```
-这样写会比下面的代码简洁:
+这样写会比下面的代码简洁:
```swift
let contentHeight = 40
@@ -310,18 +310,18 @@ if hasHeader {
// rowHeight 现在是 90
```
-第一段代码例子使用了三目条件运算, 所以一行代码就能让我们得到正确答案. 这比第二段代码简洁得多, 无需将 `rowHeight` 定义成变量, 因为它的值无需在 `if` 语句中改变.
+第一段代码例子使用了三目条件运算,所以一行代码就能让我们得到正确答案。这比第二段代码简洁得多,无需将`rowHeight`定义成变量,因为它的值无需在`if`语句中改变。
-三目条件运算提供有效率且便捷的方式来表达二选一的选择. 需要注意的事, 过度使用三目条件运算就会由简洁的代码变成难懂的代码. 我们应避免在一个组合语句使用多个三目条件运算符.
+三目条件运算提供有效率且便捷的方式来表达二选一的选择。需要注意的事,过度使用三目条件运算就会由简洁的代码变成难懂的代码。我们应避免在一个组合语句使用多个三目条件运算符。
# 区间运算符
-Swift提供了两个方便表达一个区间的值的运算符.
+Swift提供了两个方便表达一个区间的值的运算符。
## 闭区间运算符
-闭区间运算符 `a...b` 定义一个包含从 `a` 到 `b` (包括 `a` 和 `b`)的所有值的区间.
+闭区间运算符`a...b`定义一个包含从`a`到`b`(包括`a`和`b`)的所有值的区间。
-闭区间运算符在迭代一个区间的所有值时是非常有用的, 如在 `for-in` 循环中:
+闭区间运算符在迭代一个区间的所有值时是非常有用的,如在`for-in`循环中:
```swift
for index in 1...5 {
@@ -334,14 +334,14 @@ for index in 1...5 {
// 5 * 5 = 25
```
-关于 `for-in`, 请看 [控制流](Control Flow).
+关于`for-in`,请看[控制流](Control Flow)。
## 半闭区间
-半闭区间 `a..b` 定义一个从 `a` 到 `b` 但不包括 `b` 的区间.
-之所以称为半闭区间, 是因为该区间包含第一个值而不包括最后的值.
+半闭区间`a..b`定义一个从`a`到`b`但不包括`b`的区间。
+之所以称为半闭区间,是因为该区间包含第一个值而不包括最后的值。
-半闭区间的实用性在于当你使用一个0始的列表(如数组)时, 非常方便地从0数到列表的长度.
+半闭区间的实用性在于当你使用一个0始的列表(如数组)时,非常方便地从0数到列表的长度。
```swift
let names = ["Anna", "Alex", "Brian", "Jack"]
@@ -355,21 +355,21 @@ for i in 0..count {
// 第 4 个人叫 Jack
```
-> 注意: 数组有4个元素, 但 `0..count` 只数到 3 (最后一个元素的下标), 因为它是半闭区间. 关于数组, 请查阅 [数组](Arrays).
+> 注意:数组有4个元素,但`0..count`只数到 3(最后一个元素的下标),因为它是半闭区间。关于数组,请查阅[数组](Arrays)。
# 逻辑运算
-逻辑运算的操作对象是逻辑布尔值. Swift支持基于C语言的三个标准逻辑运算.
+逻辑运算的操作对象是逻辑布尔值。Swift支持基于C语言的三个标准逻辑运算。
-- 逻辑非 `!a`
+- 逻辑非`!a`
- 逻辑与 `a && b`
- 逻辑或 `a || b`
## 逻辑非
-逻辑非运算 `!a` 对一个布尔值取反, 使得 `true` 变 `false`, `false` 变 `true`.
+逻辑非运算`!a`对一个布尔值取反,使得`true`变`false`,`false`变`true`。
-它是一个前置运算符, 需出现在操作数之前, 且不加空格. 读作 `非 a`, 然后我们看以下例子:
+它是一个前置运算符,需出现在操作数之前,且不加空格。读作 `非 a`,然后我们看以下例子:
```swift
let allowedEntry = false
@@ -379,16 +379,16 @@ if !allowedEntry {
// prints "ACCESS DENIED"
```
-`if !allowedEntry`语句可以读作 "如果 非 alowed entry.", 接下一行代码只有在如果 "非 allow entry" 为 `true`, 即 `allowEntry` 为 `false` 时被执行.
+`if!allowedEntry`语句可以读作 "如果 非 alowed entry。",接下一行代码只有在如果 "非 allow entry" 为`true`,即`allowEntry`为`false`时被执行。
-在示例代码中, 小心地选择布尔常量或变量有助于代码的可读性, 并且避免使用双重逻辑非运算, 或混乱的逻辑语句.
+在示例代码中,小心地选择布尔常量或变量有助于代码的可读性,并且避免使用双重逻辑非运算,或混乱的逻辑语句。
## 逻辑与
-逻辑与 `a && b` 表达了只有 `a` 和 `b` 的值都为 `true` 时, 整个表达式的值才会是 `true` .
+逻辑与 `a && b` 表达了只有`a`和`b`的值都为`true`时,整个表达式的值才会是`true`。
-只要任意一个值为 `false`, 整个表达式的值就为 `false`. 事实上, 如果第一个值为 `false`, 那么是不去计算第二个值的, 因为它已经不可能影响整个表达式的结果了. 这被称做 "短路计算".
+只要任意一个值为`false`,整个表达式的值就为`false`。事实上,如果第一个值为`false`,那么是不去计算第二个值的,因为它已经不可能影响整个表达式的结果了。这被称做 "短路计算"。
-以下例子, 只有两个值都为值的时候才允许进入:
+以下例子,只有两个值都为值的时候才允许进入:
```swift
let enteredDoorCode = true
@@ -402,11 +402,11 @@ if enteredDoorCode && passedRetinaScan {
```
## 逻辑或
-逻辑或 `a || b` 是一个由两个连续的 `|` 组成的中置运算符. 它表示了两个逻辑表达式的其中一个为 `true`, 整个表达式就为 `true`.
+逻辑或 `a || b` 是一个由两个连续的`|`组成的中置运算符。它表示了两个逻辑表达式的其中一个为`true`,整个表达式就为`true`。
-同逻辑与运算类似, 逻辑或也是"短路计算"的, 当左端的表达式为 `true` 时, 将不计算右边的表达式了, 因为它不可能改变整个表达式的值了.
+同逻辑与运算类似,逻辑或也是"短路计算"的,当左端的表达式为`true`时,将不计算右边的表达式了,因为它不可能改变整个表达式的值了。
-以下示例代码中, 第一个布尔值 `hasDoorKey` 为 `false`, 但第二个值 `knowsOverridePassword` 为 `true`, 所以整个表达是 `true`, 于是允许进入:
+以下示例代码中,第一个布尔值`hasDoorKey`为`false`,但第二个值`knowsOverridePassword`为`true`,所以整个表达是`true`,于是允许进入:
```swift
let hasDoorKey = false
@@ -421,7 +421,7 @@ if hasDoorKey || knowsOverridePassword {
## 组合逻辑
-我们可以组合多个逻辑运算来表达一个复合逻辑:
+我们可以组合多个逻辑运算来表达一个复合逻辑:
```swift
if enteredDoorCode && passedRetinaScan || hasDoorKey || knowsOverridePassword {
@@ -432,15 +432,15 @@ if enteredDoorCode && passedRetinaScan || hasDoorKey || knowsOverridePassword {
// 输出 "Welcome!"
```
-这个例子使用了含多个 `&&` 和 `||` 的复合逻辑. 但无论怎样, `&&` 和 `||` 始终只能操作两个值. 所以这实际是三个简单逻辑连续操作的结果. 我们来解读一下:
+这个例子使用了含多个`&&`和`||`的复合逻辑。但无论怎样,`&&`和`||`始终只能操作两个值。所以这实际是三个简单逻辑连续操作的结果。我们来解读一下:
-如果我们输入了正确的密码并通过了视网膜扫描; 或者我们有一把有效的钥匙; 又或者我们知道紧急情况下重置的密码, 我们就能把门打开进入.
+如果我们输入了正确的密码并通过了视网膜扫描; 或者我们有一把有效的钥匙; 又或者我们知道紧急情况下重置的密码,我们就能把门打开进入。
-前两种情况, 我们都不满足, 所以前两个简单逻辑的结果是 `false`, 但是我们是知道紧急情况下重置的密码的, 所以整个复杂表达式的值还是 `true`.
+前两种情况,我们都不满足,所以前两个简单逻辑的结果是`false`,但是我们是知道紧急情况下重置的密码的,所以整个复杂表达式的值还是`true`。
## 使用括号来明确优先级
-为了一个复杂表达式更容易读懂, 在合适的地方使用括号来明确优先级是很有效的, 虽然它并非必要的. 在上个关于门的权限的例子中, 我们给第一个部分加个括号, 使用它看起来逻辑更明确.
+为了一个复杂表达式更容易读懂,在合适的地方使用括号来明确优先级是很有效的,虽然它并非必要的。在上个关于门的权限的例子中,我们给第一个部分加个括号,使用它看起来逻辑更明确。
```swift
if (enteredDoorCode && passedRetinaScan) || hasDoorKey || knowsOverridePassword {
@@ -451,6 +451,6 @@ if (enteredDoorCode && passedRetinaScan) || hasDoorKey || knowsOverridePassword
// prints "Welcome!"
```
-这括号使得前两个值被看成整个逻辑表达中独立的一个部分. 虽然有括号和没括号的输出结果是一样的, 但对于读代码的人来说有括号的代码更清晰.
+这括号使得前两个值被看成整个逻辑表达中独立的一个部分。虽然有括号和没括号的输出结果是一样的,但对于读代码的人来说有括号的代码更清晰。
-可读性比简洁性更重要, 请在可以让你代码变清晰地地方加个括号吧!
+可读性比简洁性更重要,请在可以让你代码变清晰地地方加个括号吧!
diff --git a/source/chapter2/23_Advanced_Operators.md b/source/chapter2/23_Advanced_Operators.md
index 1670ddf2..07f864b6 100644
--- a/source/chapter2/23_Advanced_Operators.md
+++ b/source/chapter2/23_Advanced_Operators.md
@@ -1,18 +1,18 @@
In addition to the operators described in [Basic Operators](Basic Operators), Swift provides several advanced operators that perform more complex value manipulation. These include all of the bitwise and bit shifting operators you will be familiar with from C and Objective-C.
-除了[基本操作符](Basic Operators)中所讲的运算符, Swift还有许多复杂的高级运算符, 包括了C语和Objective-C中的位运算符和移位运算.
+除了[基本操作符](Basic Operators)中所讲的运算符,Swift还有许多复杂的高级运算符,包括了C语和Objective-C中的位运算符和移位运算。
Unlike arithmetic operators in C, arithmetic operators in Swift do not overflow by default. Overflow behavior is trapped and reported as an error. To opt in to overflow behavior, use Swift’s second set of arithmetic operators that overflow by default, such as the overflow addition operator (&+). All of these overflow operators begin with an ampersand (&).
-不同于C语言中的数值计算, Swift的数值计算默认是不可溢出的. 溢出行为会被捕获并报告为错误. 你是故意的? 好吧, 你可以使用Swift为你准备的另一套默认允许溢出的数值运算符, 如可溢出加 `&+`. 所有允许溢出的运算符都是以 `&` 开始的.
+不同于C语言中的数值计算,Swift的数值计算默认是不可溢出的。溢出行为会被捕获并报告为错误。你是故意的?好吧,你可以使用Swift为你准备的另一套默认允许溢出的数值运算符,如可溢出加`&+`。所有允许溢出的运算符都是以`&`开始的。
When you define your own structures, classes, and enumerations, it can be useful to provide your own implementations of the standard Swift operators for these custom types. Swift makes it easy to provide tailored implementations of these operators and to determine exactly what their behavior should be for each type you create.
-自定义的结构, 类和枚举, 是否可以使用标准的运算符来定义操作? 当然可以! 在Swift中, 你可以为你创建的所有类型定制运算符的操作.
+自定义的结构,类和枚举,是否可以使用标准的运算符来定义操作?当然可以!在Swift中,你可以为你创建的所有类型定制运算符的操作。
You’re not just limited to the predefined operators. Swift gives you the freedom to define your own custom infix, prefix, postfix, and assignment operators, with custom precedence and associativity values. These operators can be used and adopted in your code just like any of the predefined operators, and you can even extend existing types to support the custom operators you define.
-可定制的运算符并不限于那些预设的运算符, 自定义有个性的中置, 前置, 后置及赋值运算符, 当然还有优先级和结合性. 这些运算符的实现可以运用预设的运算符, 也可以运用之前定制的运算符.
+可定制的运算符并不限于那些预设的运算符,自定义有个性的中置,前置,后置及赋值运算符,当然还有优先级和结合性。这些运算符的实现可以运用预设的运算符,也可以运用之前定制的运算符。
# Bitwise Operators
@@ -20,11 +20,11 @@ You’re not just limited to the predefined operators. Swift gives you the freed
Bitwise operators enable you to manipulate the individual raw data bits within a data structure. They are often used in low-level programming, such as graphics programming and device driver creation. Bitwise operators can also be useful when you work with raw data from external sources, such as encoding and decoding data for communication over a custom protocol.
-位操作符通常在诸如图像处理和创建设备驱动等底层开发中使用, 使用它可以单独操作数据结构中原始数据的比特位. 在使用一个自定义的协议进行通信的时候, 运用位运算符来对原始数据进行编码和解码也是非常有效的.
+位操作符通常在诸如图像处理和创建设备驱动等底层开发中使用,使用它可以单独操作数据结构中原始数据的比特位。在使用一个自定义的协议进行通信的时候,运用位运算符来对原始数据进行编码和解码也是非常有效的。
Swift supports all of the bitwise operators found in C, as described below.
-Swift支持如下所有C语言的位运算符:
+Swift支持如下所有C语言的位运算符:
## Bitwise NOT Operator
@@ -32,13 +32,13 @@ Swift支持如下所有C语言的位运算符:
The bitwise NOT operator (~) inverts all bits in a number:
-按位取反运算符 `~` 对一个操作数的每一位都取反.
+按位取反运算符`~`对一个操作数的每一位都取反。

The bitwise NOT operator is a prefix operator, and appears immediately before the value it operates on, without any white space:
-这个运算符是前置的, 所以请不加任何空格地写着操作数之前.
+这个运算符是前置的,所以请不加任何空格地写着操作数之前。
```
let initialBits: UInt8 = 0b00001111
@@ -47,11 +47,11 @@ let invertedBits = ~initialBits // 等于 0b11110000
UInt8 integers have eight bits and can store any value between 0 and 255. This example initializes a UInt8 integer with the binary value 00001111, which has its first four bits set to 0, and its second four bits set to 1. This is equivalent to a decimal value of 15.
-`UInt8` 是8位无符整型, 可以存储0~255之间的任意数. 这个例子初始化一个整型为二进制值 `00001111`(前4位为 `0`, 后4位为 `1`), 它的十进制值为 `15`.
+`UInt8`是8位无符整型,可以存储0~255之间的任意数。这个例子初始化一个整型为二进制值`00001111`(前4位为`0`,后4位为`1`),它的十进制值为`15`。
The bitwise NOT operator is then used to create a new constant called invertedBits, which is equal to initialBits, but with all of the bits inverted. Zeroes become ones, and ones become zeroes. The value of invertedBits is 11110000, which is equal to an unsigned decimal value of 240.
-使用按位取反运算 `~` 对 `initialBits` 操作, 然后赋值给 `invertedBits` 这个新常量. 这个新常量的值等于所有位都取反的 `initialBits`, 即 `1` 变成 `0`, `0` 变成 `1`, 变成了 `11110000`, 十进制值为 `240`.
+使用按位取反运算`~`对`initialBits`操作,然后赋值给`invertedBits`这个新常量。这个新常量的值等于所有位都取反的`initialBits`,即`1`变成`0`,`0`变成`1`,变成了`11110000`,十进制值为`240`。
## Bitwise AND Operator
@@ -59,13 +59,13 @@ The bitwise NOT operator is then used to create a new constant called invertedBi
The bitwise AND operator (&) combines the bits of two numbers. It returns a new number whose bits are set to 1 only if the bits were equal to 1 in both input numbers:
-按位与运算符对两个数进行操作, 然后返回一个新的数, 这个数的每个位都需要两个输入数的同一位都为1时才为1.
+按位与运算符对两个数进行操作,然后返回一个新的数,这个数的每个位都需要两个输入数的同一位都为1时才为1。

In the example below, the values of firstSixBits and lastSixBits both have four middle bits equal to 1. The bitwise AND operator combines them to make the number 00111100, which is equal to an unsigned decimal value of 60:
-以下代码, `firstSixBits` 和 `lastSixBits` 中间4个位都为1. 对它俩进行按位与运算后, 就得到了 `00111100`, 即十进制的 `60`.
+以下代码,`firstSixBits`和`lastSixBits`中间4个位都为1。对它俩进行按位与运算后,就得到了`00111100`,即十进制的`60`。
```
let firstSixBits: UInt8 = 0b11111100
@@ -79,13 +79,13 @@ let middleFourBits = firstSixBits & lastSixBits // 等于 00111100
The bitwise OR operator (|) compares the bits of two numbers. The operator returns a new number whose bits are set to 1 if the bits are equal to 1 in either input number:
-按位或运算符 `|` 比较两个数, 然后返回一个新的数, 这个数的每一位设置1的条件是两个输入数的同一位都不为0(即任意一个为1, 或都为1).
+按位或运算符`|`比较两个数,然后返回一个新的数,这个数的每一位设置1的条件是两个输入数的同一位都不为0(即任意一个为1,或都为1)。

In the example below, the values of someBits and moreBits have different bits set to 1. The bitwise OR operator combines them to make the number 11111110, which equals an unsigned decimal of 254:
-如下代码, `someBits` 和 `moreBits` 在不同位上有 `1`. 按位或运行的结果是 `11111110`, 即十进制的 `254`.
+如下代码,`someBits`和`moreBits`在不同位上有`1`。按位或运行的结果是`11111110`,即十进制的`254`。
```
let someBits: UInt8 = 0b10110010
@@ -99,13 +99,13 @@ let combinedbits = someBits | moreBits // 等于 11111110
The bitwise XOR operator, or “exclusive OR operator” (^), compares the bits of two numbers. The operator returns a new number whose bits are set to 1 where the input bits are different and are set to 0 where the input bits are the same:
-按位异或运算符 `^` 比较两个数, 然后返回一个数, 这个数的每个位设为 `1`的条件是两个输入数的同一位不同, 如果相同就设为 `0`.
+按位异或运算符`^`比较两个数,然后返回一个数,这个数的每个位设为`1`的条件是两个输入数的同一位不同,如果相同就设为`0`。

In the example below, the values of firstBits and otherBits each have a bit set to 1 in a location that the other does not. The bitwise XOR operator sets both of these bits to 1 in its output value. All of the other bits in firstBits and otherBits match and are set to 0 in the output value:
-以下代码, `firstBits` 和 `otherBits` 都有一个 `1` 跟另一个数不同的. 所以按位异或的结果是把它这些位置为 `1`, 其他都置为 `0`.
+以下代码,`firstBits`和`otherBits`都有一个`1`跟另一个数不同的。所以按位异或的结果是把它这些位置为`1`,其他都置为`0`。
```
let firstBits: UInt8 = 0b00010100
@@ -118,28 +118,28 @@ let outputBits = firstBits ^ otherBits // 等于 00010001
The bitwise left shift operator (<<) and bitwise right shift operator (>>) move all bits in a number to the left or the right by a certain number of places, according to the rules defined below.
-左移运算符 `<<` 和右移运算符 `>>` 会把一个数的所有比特位按以下定义的规则向左或向右移动指定位数.
+左移运算符`<<`和右移运算符`>>`会把一个数的所有比特位按以下定义的规则向左或向右移动指定位数。
Bitwise left and right shifts have the effect of multiplying or dividing an integer number by a factor of two. Shifting an integer’s bits to the left by one position doubles its value, whereas shifting it to the right by one position halves its value.
-按位左移和按位右移的效果相当把一个整数乘于或除于一个因子为 `2` 的整数. 向左移动一个整型的比特位相当于把这个数乘于 `2`, 向右移一位就是除于 `2`.
+按位左移和按位右移的效果相当把一个整数乘于或除于一个因子为`2`的整数。向左移动一个整型的比特位相当于把这个数乘于`2`,向右移一位就是除于`2`。
### Shifting Behavior for Unsigned Integers
### 无符整型的移位操作
The bit-shifting behavior for unsigned integers is as follows:
-对无符整型的移位的效果如下:
+对无符整型的移位的效果如下:
Existing bits are moved to the left or right by the requested number of places.
Any bits that are moved beyond the bounds of the integer’s storage are discarded.
Zeroes are inserted in the spaces left behind after the original bits are moved to the left or right.
This approach is known as a logical shift.
-已经存在的比特位向左或向右移动指定的位数. 被移出整型存储边界的的位数直接抛弃, 移动留下的空白位用零 `0` 来填充. 这种方法称为逻辑移位.
+已经存在的比特位向左或向右移动指定的位数。被移出整型存储边界的的位数直接抛弃,移动留下的空白位用零`0`来填充。这种方法称为逻辑移位。
The illustration below shows the results of 11111111 << 1 (which is 11111111 shifted to the left by 1 place), and 11111111 >> 1 (which is 11111111 shifted to the right by 1 place). Blue numbers are shifted, gray numbers are discarded, and orange zeroes are inserted:
-以下这张把展示了 `11111111 << 1` (`11111111` 向左移1位), 和 `11111111 >> 1` (`11111111` 向右移1位). 蓝色的是被移位的, 灰色是被抛弃的, 橙色的 `0` 是被填充进来的.
+以下这张把展示了 `11111111 << 1`(`11111111`向左移1位),和 `11111111 >> 1`(`11111111`向右移1位)。蓝色的是被移位的,灰色是被抛弃的,橙色的`0`是被填充进来的。

Here’s how bit shifting looks in Swift code:
@@ -154,7 +154,7 @@ shiftBits >> 2 // 00000001
```
You can use bit shifting to encode and decode values within other data types:
-你可以使用移位操作进行其他数据类型的编码和解码.
+你可以使用移位操作进行其他数据类型的编码和解码。
```
let pink: UInt32 = 0xCC6699
@@ -165,100 +165,100 @@ let blueComponent = pink & 0x0000FF // blueComponent 是 0x99, 即 153
This example uses a UInt32 constant called pink to store a Cascading Style Sheets color value for the color pink. The CSS color value #CC6699 is written as 0xCC6699 in Swift’s hexadecimal number representation. This color is then decomposed into its red (CC), green (66), and blue (99) components by the bitwise AND operator (&) and the bitwise right shift operator (>>).
-这个例子使用了一个 `UInt32` 的命名为 `pink`的常量来存储层叠样式表 `CSS` 中粉色的颜色值, `CSS`颜色`#CC6699`在Swift用十六进制`0xCC6699`来表示. 然后使用按位与(&)和按位右移就可以从这个颜色值中解析出红(CC), 绿(66), 蓝(99)三个部分.
+这个例子使用了一个`UInt32`的命名为`pink`的常量来存储层叠样式表`CSS`中粉色的颜色值,`CSS`颜色`#CC6699`在Swift用十六进制`0xCC6699`来表示。然后使用按位与(&)和按位右移就可以从这个颜色值中解析出红(CC),绿(66),蓝(99)三个部分。
The red component is obtained by performing a bitwise AND between the numbers 0xCC6699 and 0xFF0000. The zeroes in 0xFF0000 effectively “mask” the second and third bytes of 0xCC6699, causing the 6699 to be ignored and leaving 0xCC0000 as the result.
-对 `0xCC6699` 和 `0xFF0000` 进行按位与 `&` 操作就可以得到红色部分. `0xFF0000` 中的 `0` 了遮盖了 `OxCC6699` 的第二和第三个字节, 这样 `6699` 被忽略了, 只留下 `0xCC0000`.
+对`0xCC6699`和`0xFF0000`进行按位与`&`操作就可以得到红色部分。`0xFF0000`中的`0`了遮盖了`OxCC6699`的第二和第三个字节,这样`6699`被忽略了,只留下`0xCC0000`。
This number is then shifted 16 places to the right (>> 16). Each pair of characters in a hexadecimal number uses 8 bits, so a move 16 places to the right will convert 0xCC0000 into 0x0000CC. This is the same as 0xCC, which has a decimal value of 204.
-然后, 按向右移动16位, 即 `>> 16`. 十六进制中每两个字符是8比特位, 所以移动16位的结果是把 `0xCC0000` 变成 `0x0000CC`. 这和 `0xCC` 是相等的, 都是十进制的 `204`.
+然后,按向右移动16位,即 `>> 16`。十六进制中每两个字符是8比特位,所以移动16位的结果是把`0xCC0000`变成`0x0000CC`。这和`0xCC`是相等的,都是十进制的`204`。
Similarly, the green component is obtained by performing a bitwise AND between the numbers 0xCC6699 and 0x00FF00, which gives an output value of 0x006600. This output value is then shifted eight places to the right, giving a a value of 0x66, which has a decimal value of 102.
-同样的, 绿色部分来自于 `0xCC6699` 和 `0x00FF00` 的按位操作得到 `0x006600`. 然后向右移动8們, 得到 `0x66`, 即十进制的 `102`.
+同样的,绿色部分来自于`0xCC6699`和`0x00FF00`的按位操作得到`0x006600`。然后向右移动8們,得到`0x66`,即十进制的`102`。
Finally, the blue component is obtained by performing a bitwise AND between the numbers 0xCC6699 and 0x0000FF, which gives an output value of 0x000099. There’s no need to shift this to the right, as 0x000099 already equals 0x99, which has a decimal value of 153.
-最后, 蓝色部分对 `0xCC6699` 和 `0x0000FF` 进行按位与运算, 得到 `0x000099`, 无需向右移位了, 所以结果就是 `0x99`, 即十进制的 `153`.
+最后,蓝色部分对`0xCC6699`和`0x0000FF`进行按位与运算,得到`0x000099`,无需向右移位了,所以结果就是`0x99`,即十进制的`153`。
### Shifting Behavior for Signed Integers
### 有符整型的移位操作
The shifting behavior is more complex for signed integers than for unsigned integers, because of the way signed integers are represented in binary. (The examples below are based on 8-bit signed integers for simplicity, but the same principles apply for signed integers of any size.)
-有符整型的移位操作相对复杂得多, 因为正负号也是用二进制位表示的. (这里举的例子虽然都是8位的, 但它的原理是通用的.)
+有符整型的移位操作相对复杂得多,因为正负号也是用二进制位表示的。(这里举的例子虽然都是8位的,但它的原理是通用的。)
Signed integers use their first bit (known as the sign bit) to indicate whether the integer is positive or negative. A sign bit of 0 means positive, and a sign bit of 1 means negative.
-有符整型通过第1个比特位(称为符号位)来表达这个整数是正数还是负数. `0` 代表正数, `1` 代表负数.
+有符整型通过第1个比特位(称为符号位)来表达这个整数是正数还是负数。`0`代表正数,`1`代表负数。
The remaining bits (known as the value bits) store the actual value. Positive numbers are stored in exactly the same way as for unsigned integers, counting upwards from 0. Here’s how the bits inside an Int8 look for the number 4:
-其余的比特位(称为数值位)存储其实值. 有符正整数和无符正整数在计算机里的存储结果是一样的, 下来我们来看 `+4` 内部的二进制结构.
+其余的比特位(称为数值位)存储其实值。有符正整数和无符正整数在计算机里的存储结果是一样的,下来我们来看`+4`内部的二进制结构。

The sign bit is 0 (meaning “positive”), and the seven value bits are just the number 4, written in binary notation.
-符号位为 `0`, 代表正数, 另外7比特位二进制表示的实际值就刚好是 `4`.
+符号位为`0`,代表正数,另外7比特位二进制表示的实际值就刚好是`4`。
Negative numbers, however, are stored differently. They are stored by subtracting their absolute value from 2 to the power of n, where n is the number of value bits. An eight-bit number has seven value bits, so this means 2 to the power of 7, or 128.
-负数呢, 跟正数不同. 负数存储的是2的n次方减去它的绝对值, n为数值位的位数. 一个8比特的数有7个数值位, 所以是2的7次方, 即128.
+负数呢,跟正数不同。负数存储的是2的n次方减去它的绝对值,n为数值位的位数。一个8比特的数有7个数值位,所以是2的7次方,即128。
Here’s how the bits inside an Int8 look for the number -4:
-我们来看 `-4` 存储的二进制结构.
+我们来看`-4`存储的二进制结构。

This time, the sign bit is 1 (meaning “negative”), and the seven value bits have a binary value of 124 (which is 128 - 4):
-现在符号位为 `1`, 代表负数, 7个数值位要表达的二进制值是124, 即128 - 4.
+现在符号位为`1`,代表负数,7个数值位要表达的二进制值是124,即128 - 4。

The encoding for negative numbers is known as a two’s complement representation. It may seem an unusual way to represent negative numbers, but it has several advantages.
-负数的编码方式称为二进制补码表示. 这种表示方式看起来很奇怪, 但它有几个优点.
+负数的编码方式称为二进制补码表示。这种表示方式看起来很奇怪,但它有几个优点。
First, you can add -1 to -4, simply by performing a standard binary addition of all eight bits (including the sign bit), and discarding anything that doesn’t fit in the eight bits once you’re done:
-首先, 只需要对全部8个比特位(包括符号)做标准的二进制加法就可以完成 `-1 + -4` 的操作, 忽略加法过程产生的超过8个比特位表达的任何信息.
+首先,只需要对全部8个比特位(包括符号)做标准的二进制加法就可以完成 `-1 + -4` 的操作,忽略加法过程产生的超过8个比特位表达的任何信息。

Second, the two’s complement representation also lets you shift the bits of negative numbers to the left and right like positive numbers, and still end up doubling them for every shift you make to the left, or halving them for every shift you make to the right. To achieve this, an extra rule is used when signed integers are shifted to the right:
-第二, 由于使用二进制补码表示, 我们可以和正数一样对负数进行按位左移右移的, 同样也是左移1位时乘于 `2`, 右移1位时除于 `2`. 要达到此目的, 对有符整型的右移有一个特别的要求:
+第二,由于使用二进制补码表示,我们可以和正数一样对负数进行按位左移右移的,同样也是左移1位时乘于`2`,右移1位时除于`2`。要达到此目的,对有符整型的右移有一个特别的要求:
When you shift signed integers to the right, apply the same rules as for unsigned integers, but fill any empty bits on the left with the sign bit, rather than with a zero.
-对有符整型按位右移时, 使用符号位(正数为 `0`, 负数为 `1`)填充空白位.
+对有符整型按位右移时,使用符号位(正数为`0`,负数为`1`)填充空白位。

This action ensures that signed integers have the same sign after they are shifted to the right, and is known as an arithmetic shift.
-这就确保了在右移的过程中, 有符整型的符号不会发生变化. 这称为算术移位.
+这就确保了在右移的过程中,有符整型的符号不会发生变化。这称为算术移位。
Because of the special way that positive and negative numbers are stored, shifting either of them to the right moves them closer to zero. Keeping the sign bit the same during this shift means that negative integers remain negative as their value moves closer to zero.
-正因为正数和负数特殊的存储方式, 向右移位使它接近于 `0`. 移位过程中保持符号会不变, 负数在接近 `0` 的过程中一直是负数.
+正因为正数和负数特殊的存储方式,向右移位使它接近于`0`。移位过程中保持符号会不变,负数在接近`0`的过程中一直是负数。
# Overflow Operators
# 溢出运算符
If you try to insert a number into an integer constant or variable that cannot hold that value, by default Swift reports an error rather than allowing an invalid value to be created. This behavior gives extra safety when you work with numbers that are too large or too small.
-默认情况下, 当你往一个整型常量或变量赋于一个它不能承载的大数时, Swift不会让你这么干的, 它会报错. 这样, 在操作过大或过小的数的时候就很安全了.
+默认情况下,当你往一个整型常量或变量赋于一个它不能承载的大数时,Swift不会让你这么干的,它会报错。这样,在操作过大或过小的数的时候就很安全了。
For example, the Int16 integer type can hold any signed integer number between -32768 and 32767. Trying to set a UInt16 constant or variable to a number outside of this range causes an error:
-例如, `Int16` 整型能承载的整数范围是 `-32768` 到 `32767`, 如果给它赋上超过这个范围的数, 就会报错:
+例如,`Int16`整型能承载的整数范围是`-32768`到`32767`,如果给它赋上超过这个范围的数,就会报错:
```
var potentialOverflow = Int16.max
@@ -269,11 +269,11 @@ potentialOverflow += 1
Providing error handling when values get too large or too small gives you much more flexibility when coding for boundary value conditions.
-对过大或过小的数值进行错误处理让你的数值边界条件更灵活.
+对过大或过小的数值进行错误处理让你的数值边界条件更灵活。
However, when you specifically want an overflow condition to truncate the number of available bits, you can opt in to this behavior rather than triggering an error. Swift provides five arithmetic overflow operators that opt in to the overflow behavior for integer calculations. These operators all begin with an ampersand (&):
-当然, 你有意在溢出时对有效位进行截断, 你可采用溢出运算, 而非错误处理. Swfit为整型计算提供了5个 `&` 符号开头的溢出运算符.
+当然,你有意在溢出时对有效位进行截断,你可采用溢出运算,而非错误处理。Swfit为整型计算提供了5个`&`符号开头的溢出运算符。
- 溢出加法 `&+`
- 溢出减法 `&-`
@@ -286,7 +286,7 @@ However, when you specifically want an overflow condition to truncate the number
Here’s an example of what happens when an unsigned value is allowed to overflow, using the overflow addition operator (&+):
-下面例子使用了溢出加法 `&+` 来解剖的无符整数的上溢出
+下面例子使用了溢出加法`&+`来解剖的无符整数的上溢出
```
var willOverflow = UInt8.max
@@ -297,7 +297,7 @@ willOverflow = willOverflow &+ 1
The variable willOverflow is initialized with the largest value a UInt8 can hold (255, or 11111111 in binary). It is then incremented by 1 using the overflow addition operator (&+). This pushes its binary representation just over the size that a UInt8 can hold, causing it to overflow beyond its bounds, as shown in the diagram below. The value that remains within the bounds of the UInt8 after the overflow addition is 00000000, or zero:
-`willOverflow` 用 `Int8` 所能承载的最大值 `255` (二进制 `11111111`), 然后用 `&+` 加1. 然后 `UInt8` 就无法表达这个新值的二进制了, 也就导致了这个新值上溢出了, 大家可以看下图. 溢出后, 新值在 `UInt8` 的承载范围内的那部分是 `00000000`, 也就是 `0`.
+`willOverflow`用`Int8`所能承载的最大值`255`(二进制`11111111`),然后用`&+`加1。然后`UInt8`就无法表达这个新值的二进制了,也就导致了这个新值上溢出了,大家可以看下图。溢出后,新值在`UInt8`的承载范围内的那部分是`00000000`,也就是`0`。

@@ -305,11 +305,11 @@ The variable willOverflow is initialized with the largest value a UInt8 can hold
## 值的下溢出
Numbers can also become too small to fit in their type’s maximum bounds. Here’s an example.
-数值也有可能因为太小而越界. 举个例子:
+数值也有可能因为太小而越界。举个例子:
The smallest value that a UInt8 can hold is 0 (which is 00000000 in eight-bit binary form). If you subtract 1 from 00000000 using the overflow subtraction operator, the number will overflow back round to 11111111, or 255 in decimal:
-`UInt8` 的最小值是 `0` (二进制为 `00000000`). 使用 `&-` 进行溢出减1, 就会得到二进制的 `11111111` 即十进制的 `255`.
+`UInt8`的最小值是`0`(二进制为`00000000`)。使用`&-`进行溢出减1,就会得到二进制的`11111111`即十进制的`255`。

@@ -326,13 +326,13 @@ willUnderflow = willUnderflow &- 1
A similar underflow occurs for signed integers. All subtraction for signed integers is performed as straight binary subtraction, with the sign bit included as part of the numbers being subtracted, as described in Bitwise Left and Right Shift Operators. The smallest number that an Int8 can hold is -128, which is 10000000 in binary. Subtracting 1 from this binary number with the overflow operator gives a binary value of 01111111, which toggles the sign bit and gives positive 127, the largest positive value that an Int8 can hold:
-有符整型也有类似的下溢出, 有符整型所有的减法也都是对包括在符号位在内的二进制数进行二进制减法的, 这在 "按位左移/右移运算符" 一节提到过. 最小的有符整数是 `-128`, 即二进制的 `10000000`. 用溢出减法减去去1后, 变成了 `01111111`, 即UInt8所能承载的最大整数 `127`.
+有符整型也有类似的下溢出,有符整型所有的减法也都是对包括在符号位在内的二进制数进行二进制减法的,这在 "按位左移/右移运算符" 一节提到过。最小的有符整数是`-128`,即二进制的`10000000`。用溢出减法减去去1后,变成了`01111111`,即UInt8所能承载的最大整数`127`。

Here’s the same thing in Swift code:
-来看看Swift代码:
+来看看Swift代码:
```
var signedUnderflow = Int8.min
@@ -346,9 +346,9 @@ The end result of the overflow and underflow behavior described above is that fo
## Division by Zero
## 除零溢出
-Dividing a number by zero (i / 0), or trying to calculate remainder by zero (i % 0), causes an error:
+Dividing a number by zero(i / 0), or trying to calculate remainder by zero(i % 0), causes an error:
-一个数除于0 `i / 0`, 或者对0求余数 `i % 0`, 就会产生一个错误.
+一个数除于0 `i / 0`,或者对0求余数 `i % 0`,就会产生一个错误。
```
let x = 1
@@ -357,7 +357,7 @@ let y = x / 0
However, the overflow versions of these operators (&/ and &%) return a value of zero if you divide by zero:
-使用它们对应的可溢出的版本的运算符 `&/` 和 `&%` 进行除0操作时就会得到 `0` 值.
+使用它们对应的可溢出的版本的运算符`&/`和`&%`进行除0操作时就会得到`0`值。
```
let x = 1
@@ -371,15 +371,15 @@ let y = x &/ 0
Operator precedence gives some operators higher priority than others; these operators are calculated first.
-运算符的优先级使得一些运算符优先于其他运算符, 高优先级的运算符会先被计算.
+运算符的优先级使得一些运算符优先于其他运算符,高优先级的运算符会先被计算。
Operator associativity defines how operators of the same precedence are grouped together (or associated)—either grouped from the left, or grouped from the right. Think of it as meaning “they associate with the expression to their left,” or “they associate with the expression to their right.”
-结合性定义相同优先级的运算符在一起时是怎么组合或关联的, 是和左边的一组呢, 还是和右边的一组. 意思就是, 到底是和左边的表达式结合呢, 还是和右边的表达式结合?
+结合性定义相同优先级的运算符在一起时是怎么组合或关联的,是和左边的一组呢,还是和右边的一组。意思就是,到底是和左边的表达式结合呢,还是和右边的表达式结合?
It is important to consider each operator’s precedence and associativity when working out the order in which a compound expression will be calculated. Here’s an example. Why does the following expression equal 4?
-在混合表达式中, 运算符的优先级和结合性是非常重要的. 举个例子, 为什么下列表达式的结果为 `4`?
+在混合表达式中,运算符的优先级和结合性是非常重要的。举个例子,为什么下列表达式的结果为`4`?
```
2 + 3 * 4 % 5
@@ -388,7 +388,7 @@ It is important to consider each operator’s precedence and associativity when
Taken strictly from left to right, you might expect this to read as follows:
-如果严格地从左计算到右, 计算过程会是这样:
+如果严格地从左计算到右,计算过程会是这样:
- 2 plus 3 equals 5;
- 2 + 3 = 5
@@ -399,18 +399,18 @@ Taken strictly from left to right, you might expect this to read as follows:
However, the actual answer is 4, not 0. Higher-precedence operators are evaluated before lower-precedence ones. In Swift, as in C, the multiplication operator (*) and the remainder operator (%) have a higher precedence than the addition operator (+). As a result, they are both evaluated before the addition is considered.
-但是正确答案是 `4` 而不是 `0`. 优先级高的运算符要先计算, 在Swift和C语言中, 都是先乘除后加减的. 所以, 执行完乘法和求余运算才能执行加减运算.
+但是正确答案是`4`而不是`0`。优先级高的运算符要先计算,在Swift和C语言中,都是先乘除后加减的。所以,执行完乘法和求余运算才能执行加减运算。
However, multiplication and remainder have the same precedence as each other. To work out the exact evaluation order to use, you also need to consider their associativity. Multiplication and remainder both associate with the expression to their left. Think of this as adding implicit parentheses around these parts of the expression, starting from their left:
-乘法和求余拥有相同的优先级, 在运算过程中, 我们还需要结合性, 乘法和求余运算都是左结合的. 这相当于在表达式中有隐藏的括号让运算从左开始.
+乘法和求余拥有相同的优先级,在运算过程中,我们还需要结合性,乘法和求余运算都是左结合的。这相当于在表达式中有隐藏的括号让运算从左开始。
```
2 + ((3 * 4) % 5)
```
(3 * 4) is 12, so this is equivalent to:
-3 * 4 = 12, 所以这相当于:
+3 * 4 = 12,所以这相当于:
```
@@ -418,7 +418,7 @@ However, multiplication and remainder have the same precedence as each other. To
```
(12 % 5) is 2, so this is equivalent to:
-12 % 5 = 2, 所这又相当于
+12 % 5 = 2,所这又相当于
```
2 + 2
@@ -426,11 +426,11 @@ However, multiplication and remainder have the same precedence as each other. To
This calculation yields the final answer of 4.
-计算结果为 4.
+计算结果为 4。
For a complete list of Swift operator precedences and associativity rules, see [Expressions](Expressions).
-查阅Swift运算符的优先级和结合性的完整列表, 请看 [表达式](Expressions).
+查阅Swift运算符的优先级和结合性的完整列表,请看[表达式](Expressions)。
> NOTE
@@ -438,22 +438,22 @@ For a complete list of Swift operator precedences and associativity rules, see [
> Swift’s operator precedences and associativity rules are simpler and more predictable than those found in C and Objective-C. However, this means that they are not the same as in C-based languages. Be careful to ensure that operator interactions still behave in the way you intend when porting existing code to Swift.
-> Swift的运算符较C语言和Objective-C来得更简单和保守, 这意味着跟基于C的语言可能不一样. 所以, 在移植已有代码到Swift时, 注意去确保代码按你想的那样去执行.
+> Swift的运算符较C语言和Objective-C来得更简单和保守,这意味着跟基于C的语言可能不一样。所以,在移植已有代码到Swift时,注意去确保代码按你想的那样去执行。
# Operator Functions
# 运算符函数
Classes and structures can provide their own implementations of existing operators. This is known as overloading the existing operators.
-让已有的运算符也可以对自定义的类和结构进行运算, 这称为运算符重载.
+让已有的运算符也可以对自定义的类和结构进行运算,这称为运算符重载。
The example below shows how to implement the arithmetic addition operator (+) for a custom structure. The arithmetic addition operator is a binary operator because it operates on two targets and is said to be infix because it appears in between those two targets.
The example defines a Vector2D structure for a two-dimensional position vector (x, y), followed by a definition of an operator function to add together instances of the Vector2D structure:
-这个例子展示了如何用 `+` 让一个自定义的结构做加法. 算术运算符 `+` 是一个两目运算符, 因为它有两个操作数, 而且它必须出现在两个操作数之间.
+这个例子展示了如何用`+`让一个自定义的结构做加法。算术运算符`+`是一个两目运算符,因为它有两个操作数,而且它必须出现在两个操作数之间。
-例子中定义了一个名为 `Vector2D` 的二维坐标向量 `(x, y)` 的结构, 然后定义了让两个 `Vector2D` 的对象相加的运算符函数.
+例子中定义了一个名为`Vector2D`的二维坐标向量 `(x,y)` 的结构,然后定义了让两个`Vector2D`的对象相加的运算符函数。
```
struct Vector2D {
@@ -466,15 +466,15 @@ struct Vector2D {
The operator function is defined as a global function called +, which takes two input parameters of type Vector2D and returns a single output value, also of type Vector2D. You implement an infix operator by writing the @infix attribute before the func keyword when declaring the operator function.
-该运算符函数定义了一个全局的 `+` 函数, 这个函数需要两个 `Vector2D` 类型的参数, 返回值也是 `Vector2D` 类型. 需要定义和实现一个中置运算的时候, 在关键字 `func` 之前写上属性 `@infix` 就可以了.
+该运算符函数定义了一个全局的`+`函数,这个函数需要两个`Vector2D`类型的参数,返回值也是`Vector2D`类型。需要定义和实现一个中置运算的时候,在关键字`func`之前写上属性 `@infix` 就可以了。
In this implementation, the input parameters are named left and right to represent the Vector2D instances that will be on the left side and right side of the + operator. The function returns a new Vector2D instance, whose x and y properties are initialized with the sum of the x and y properties from the two Vector2D instances that are added together.
-在这个代码实现中, 参数被命名为了 `left` 和 `right`, 代表 `+` 左边和右边的两个 `Vector2D` 对象. 函数返回了一个新的 `Vector2D` 的对象, 这个对象的 `x` 和 `y` 分别等于两个参数对象的 `x` 和 `y` 的和.
+在这个代码实现中,参数被命名为了`left`和`right`,代表`+`左边和右边的两个`Vector2D`对象。函数返回了一个新的`Vector2D`的对象,这个对象的`x`和`y`分别等于两个参数对象的`x`和`y`的和。
The function is defined globally, rather than as a method on the Vector2D structure, so that it can be used as an infix operator between existing Vector2D instances:
-这个函数是全局的, 而不是 `Vector2D` 结构的成员方法, 所以任意两个 `Vector2D` 对象都可以使用这个中置运算符.
+这个函数是全局的,而不是`Vector2D`结构的成员方法,所以任意两个`Vector2D`对象都可以使用这个中置运算符。
```
let vector = Vector2D(x: 3.0, y: 1.0)
@@ -485,7 +485,7 @@ let combinedVector = vector + anotherVector
This example adds together the vectors (3.0, 1.0) and (2.0, 4.0) to make the vector (5.0, 5.0), as illustrated below.
-这个例子实现两个向量 `(3.0, 1.0)` 和 `(2.0, 4.0)` 相加, 得到向量 `(5.0, 5.0)` 的过程. 如下图示:
+这个例子实现两个向量 `(3。0,1。0)` 和 `(2。0,4。0)` 相加,得到向量 `(5。0,5。0)` 的过程。如下图示:

@@ -496,9 +496,9 @@ The example shown above demonstrates a custom implementation of a binary infix o
You implement a prefix or postfix unary operator by writing the @prefix or @postfix attribute before the func keyword when declaring the operator function:
-上个例子演示了一个双目中置运算符的自定义实现, 同样我们也可以玩标准单目运算符的实现. 单目运算符只有一个操作数, 在操作数之前就是前置的, 如 `-a`; 在操作数之后就是后置的, 如 `i++`.
+上个例子演示了一个双目中置运算符的自定义实现,同样我们也可以玩标准单目运算符的实现。单目运算符只有一个操作数,在操作数之前就是前置的,如`-a`; 在操作数之后就是后置的,如`i++`。
-实现一个前置或后置运算符时, 在定义该运算符的时候于关键字 `func` 之前标注 `@prefix` 或 `@postfix` 属性.
+实现一个前置或后置运算符时,在定义该运算符的时候于关键字`func`之前标注 `@prefix` 或 `@postfix` 属性。
```
@prefix func - (vector: Vector2D) -> Vector2D {
@@ -508,11 +508,11 @@ You implement a prefix or postfix unary operator by writing the @prefix or @post
The example above implements the unary minus operator (-a) for Vector2D instances. The unary minus operator is a prefix operator, and so this function has to be qualified with the @prefix attribute.
-这段代码为 `Vector2D` 类型提供了单目减运算 `-a`, `@prefix` 表明这是个前置运算符. 这个运算符,
+这段代码为`Vector2D`类型提供了单目减运算`-a`,`@prefix` 表明这是个前置运算符。这个运算符,
For simple numeric values, the unary minus operator converts positive numbers into their negative equivalent and vice versa. The corresponding implementation for Vector2D instances performs this operation on both the x and y properties:
-对于数值, 单目减运算符可以把正数变负数, 把负数变正数. 对于 `Vector2D`, 单目减运算将其 `x` 和 `y` 都进进行单目减运算.
+对于数值,单目减运算符可以把正数变负数,把负数变正数。对于`Vector2D`,单目减运算将其`x`和`y`都进进行单目减运算。
```
let positive = Vector2D(x: 3.0, y: 4.0)
@@ -529,7 +529,7 @@ Compound assignment operators combine assignment (=) with another operation. For
The example below implements an addition assignment operator function for Vector2D instances:
-组合赋值是其他运算符和赋值运算符一起执行的运算. 如 `+=` 把加运算和赋值运算组合成一个操作. 实现一个组合赋值符号需要使用 `@assignment` 属性,
+组合赋值是其他运算符和赋值运算符一起执行的运算。如`+=`把加运算和赋值运算组合成一个操作。实现一个组合赋值符号需要使用 `@assignment` 属性,
```
@assignment func += (inout left: Vector2D, right: Vector2D) {
@@ -539,7 +539,7 @@ The example below implements an addition assignment operator function for Vector
Because an addition operator was defined earlier, you don’t need to reimplement the addition process here. Instead, the addition assignment operator function takes advantage of the existing addition operator function, and uses it to set the left value to be the left value plus the right value:
-因为加法运算在之前定义过了, 这里无需重新定义. 所以, 加赋运算符函数使用已经存在的高级加法运算符函数来执行左值加右值的运算.
+因为加法运算在之前定义过了,这里无需重新定义。所以,加赋运算符函数使用已经存在的高级加法运算符函数来执行左值加右值的运算。
```
var original = Vector2D(x: 1.0, y: 2.0)
@@ -550,7 +550,7 @@ original += vectorToAdd
You can combine the @assignment attribute with either the @prefix or @postfix attribute, as in this implementation of the prefix increment operator (++a) for Vector2D instances:
-你可以将 `@assignment` 属性和 `@prefix` 或 `@postfix` 属性起来组合, 实现一个 `Vector2D` 的前置运算符.
+你可以将 `@assignment` 属性和 `@prefix` 或 `@postfix` 属性起来组合,实现一个`Vector2D`的前置运算符。
```
@prefix @assignment func ++ (inout vector: Vector2D) -> Vector2D {
@@ -561,7 +561,7 @@ You can combine the @assignment attribute with either the @prefix or @postfix at
The prefix increment operator function above takes advantage of the addition assignment operator defined earlier. It adds a Vector2D with x and y values of 1.0 to the Vector2D on which it is called, and returns the result:
-这个前置使用了已经定义好的高级加赋运算, 将自己加上一个值为 `(1.0, 1.0)` 的对象然后赋给自己, 然后再将自己返回.
+这个前置使用了已经定义好的高级加赋运算,将自己加上一个值为 `(1。0,1。0)` 的对象然后赋给自己,然后再将自己返回。
```
var toIncrement = Vector2D(x: 3.0, y: 4.0)
@@ -576,18 +576,18 @@ let afterIncrement = ++toIncrement
> It is not possible to overload the default assignment operator (=). Only the compound assignment operators can be overloaded. Similarly, the ternary conditional operator (a ? b : c) cannot be overloaded.
-> 默认的赋值符是不可重载的. 只有组合赋值符可以重载. 三目条件运算符 `a ? b : c` 也是不可重载.
+> 默认的赋值符是不可重载的。只有组合赋值符可以重载。三目条件运算符 `a?b:c` 也是不可重载。
## Equivalence Operators
## 比较运算符
Custom classes and structures do not receive a default implementation of the equivalence operators, known as the “equal to” operator (==) and “not equal to” operator (!=). It is not possible for Swift to guess what would qualify as “equal” for your own custom types, because the meaning of “equal” depends on the roles that those types play in your code.
-Swift无所知道自定义类型是否相等或不等, 因为等于或者不等于由你的代码说了算了. 所以自定义的类和结构要使用比较符 `==` 或 `!=` 就需要重载.
+Swift无所知道自定义类型是否相等或不等,因为等于或者不等于由你的代码说了算了。所以自定义的类和结构要使用比较符`==`或`!=`就需要重载。
To use the equivalence operators to check for equivalence of your own custom type, provide an implementation of the operators in the same way as for other infix operators:
-定义相等运算符函数跟定义其他中置运算符雷同:
+定义相等运算符函数跟定义其他中置运算符雷同:
```
@infix func == (left: Vector2D, right: Vector2D) -> Bool {
@@ -601,11 +601,11 @@ To use the equivalence operators to check for equivalence of your own custom typ
The above example implements an “equal to” operator (==) to check if two Vector2D instances have equivalent values. In the context of Vector2D, it makes sense to consider “equal” as meaning “both instances have the same x values and y values”, and so this is the logic used by the operator implementation. The example also implements the “not equal to” operator (!=), which simply returns the inverse of the result of the “equal to” operator.
-上述代码实现了相等运算符 `==` 来判断两个 `Vector2D` 对象是否有相等的值, 相等的概念就是他们有相同的 `x` 值和相同的 `y` 值, 我们就用这个逻辑来实现. 接着使用 `==` 的结果实现了不相等运算符 `!=`.
+上述代码实现了相等运算符`==`来判断两个`Vector2D`对象是否有相等的值,相等的概念就是他们有相同的`x`值和相同的`y`值,我们就用这个逻辑来实现。接着使用`==`的结果实现了不相等运算符`!=`。
You can now use these operators to check whether two Vector2D instances are equivalent:
-现在我们可以使用这两个运算符来判断两个 `Vector2D` 对象是否相等.
+现在我们可以使用这两个运算符来判断两个`Vector2D`对象是否相等。
```
let twoThree = Vector2D(x: 2.0, y: 3.0)
@@ -621,11 +621,11 @@ if twoThree == anotherTwoThree {
You can declare and implement your own custom operators in addition to the standard operators provided by Swift. Custom operators can be defined only with the characters / = - + * % < > ! & | ^ . ~.
-标准的运算符不够玩, 那你可以声明一些个性的运算符, 但个性的运算符只能使用这些字符 `/ = - + * % < > ! & | ^ . ~`.
+标准的运算符不够玩,那你可以声明一些个性的运算符,但个性的运算符只能使用这些字符 `/ = - + * % < >!& | ^。~`。
New operators are declared at a global level using the operator keyword, and can be declared as prefix, infix or postfix:
-新的运算符声明需在全局域使用 `operator` 关键字声明, 可以声明为前置, 中置或后置的.
+新的运算符声明需在全局域使用`operator`关键字声明,可以声明为前置,中置或后置的。
```
operator prefix +++ {}
@@ -633,7 +633,7 @@ operator prefix +++ {}
The example above defines a new prefix operator called +++. This operator does not have an existing meaning in Swift, and so it is given its own custom meaning below in the specific context of working with Vector2D instances. For the purposes of this example, +++ is treated as a new “prefix doubling incrementer” operator. It doubles the x and y values of a Vector2D instance, by adding the vector to itself with the addition assignment operator defined earlier:
-这段代码定义了一个新的前置运算符叫 `+++`, 此前Swift并不存在这个运算符. 此处为了演示, 我们让 `+++` 对 `Vector2D` 对象的操作定义为 `双自增` 这样一个独有的操作, 这个操作使用了之前定义的加赋运算实现了自已加上自己然后返回的运算.
+这段代码定义了一个新的前置运算符叫`+++`,此前Swift并不存在这个运算符。此处为了演示,我们让`+++`对`Vector2D`对象的操作定义为 `双自增` 这样一个独有的操作,这个操作使用了之前定义的加赋运算实现了自已加上自己然后返回的运算。
```
@prefix @assignment func +++ (inout vector: Vector2D) -> Vector2D {
@@ -658,19 +658,19 @@ let afterDoubling = +++toBeDoubled
Custom infix operators can also specify a precedence and an associativity. See [Precedence and Associativity](#PrecedenceandAssociativity) for an explanation of how these two characteristics affect an infix operator’s interaction with other infix operators.
-可以为自定义的中置运算符指定优先级和结合性. 可以回头看看 [优先级和结合性](#PrecedenceandAssociativity) 解释这两个因素是如何影响多种中置运算符混合的表达式的计算的.
+可以为自定义的中置运算符指定优先级和结合性。可以回头看看[优先级和结合性](#PrecedenceandAssociativity)解释这两个因素是如何影响多种中置运算符混合的表达式的计算的。
The possible values for associativity are left, right, and none. Left-associative operators associate to the left if written next to other left-associative operators of the same precedence. Similarly, right-associative operators associate to the right if written next to other right-associative operators of the same precedence. Non-associative operators cannot be written next to other operators with the same precedence.
-结合性(associativity)的值可取的值有 `left`, `right` 和 `none`. 左结合运算符跟其他优先级相同的左结合运算符写在一起时, 会跟左边的操作数结合. 同理, 右结合运算符会跟右边的操作数结合. 而非结合运算符不能跟其他相同优先级的运算符写在一起.
+结合性(associativity)的值可取的值有`left`,`right`和`none`。左结合运算符跟其他优先级相同的左结合运算符写在一起时,会跟左边的操作数结合。同理,右结合运算符会跟右边的操作数结合。而非结合运算符不能跟其他相同优先级的运算符写在一起。
The associativity value defaults to none if it is not specified. The precedence value defaults to 100 if it is not specified.
-结合性(associativity)的值默认为 `none`, 优先级(precedence)默认为 `100`.
+结合性(associativity)的值默认为`none`,优先级(precedence)默认为`100`。
The following example defines a new custom infix operator called +-, with left associativity and a precedence of 140:
-以下例子定义了一个新的中置符 `+-`, 是左结合的 `left`, 优先级为 `140`.
+以下例子定义了一个新的中置符`+-`,是左结合的`left`,优先级为`140`。
```
operator infix +- { associativity left precedence 140 }
@@ -685,4 +685,4 @@ let plusMinusVector = firstVector +- secondVector
This operator adds together the x values of two vectors, and subtracts the y value of the second vector from the first. Because it is in essence an “additive” operator, it has been given the same associativity and precedence values (left and 140) as default additive infix operators such as + and -. For a complete list of the default Swift operator precedence and associativity settings, see [Expressions](Expressions).
-这个运算符把两个向量的 `x` 相加, 把向量的 `y` 相减. 因为他实际是属于加减运算, 所以让它保持了和加法一样的结合性和优先级 (`left` 和 `140`). 查阅完整的Swift默认结合性和优先级的设置, 请移步 [表达式](Expressions);
\ No newline at end of file
+这个运算符把两个向量的`x`相加,把向量的`y`相减。因为他实际是属于加减运算,所以让它保持了和加法一样的结合性和优先级(`left`和`140`)。查阅完整的Swift默认结合性和优先级的设置,请移步[表达式](Expressions);
\ No newline at end of file