diff --git a/source/chapter2/01_The_Basics.md b/source/chapter2/01_The_Basics.md index c4f7d6f6..0a21b78b 100755 --- a/source/chapter2/01_The_Basics.md +++ b/source/chapter2/01_The_Basics.md @@ -638,12 +638,13 @@ if let actualNumber = Int(possibleNumber) { 你可以在可选绑定中使用常量和变量。如果你想在`if`语句的第一个分支中操作`actualNumber`的值,你可以改成`if var actualNumber`,这样可选类型包含的值就会被赋给一个变量而非常量。 -多个可选绑定可以用逗号分隔,作为一列表达式出现在一个`if`语句中。 +你可以包含多个可选绑定在`if`语句中,并使用`where`子句做布尔值判断。 ```swift -if let constantName = someOptional, anotherConstantName = someOtherOptional { - statements +if let firstNumber = Int("4"), secondNumber = Int("42") where firstNumber < secondNumber { + print("\(firstNumber) < \(secondNumber)") } +// prints "4 < 42" ``` diff --git a/source/chapter2/03_Strings_and_Characters.md b/source/chapter2/03_Strings_and_Characters.md index 54f8116b..2313f2bb 100755 --- a/source/chapter2/03_Strings_and_Characters.md +++ b/source/chapter2/03_Strings_and_Characters.md @@ -291,7 +291,7 @@ print("unusualMenagerie has \(unusualMenagerie.characters.count) characters") 注意在 Swift 中,使用可拓展的字符群集作为`Character`值来连接或改变字符串时,并不一定会更改字符串的字符数量。 -例如,如果你用四个字符的单词`cafe`初始化一个新的字符串,然后添加一个`COMBINING ACTUE ACCENT`(`U+0301`)作为字符串的结尾。最终这个字符串的字符数量仍然是`4`,因为第四个字符是`e`,而不是`e`: +例如,如果你用四个字符的单词`cafe`初始化一个新的字符串,然后添加一个`COMBINING ACTUE ACCENT`(`U+0301`)作为字符串的结尾。最终这个字符串的字符数量仍然是`4`,因为第四个字符是`é`,而不是`e`: ```swift var word = "cafe"