From a6622014688a07e18f9c3ff7924c6d872a3a2e9a Mon Sep 17 00:00:00 2001 From: sunorry Date: Fri, 25 Sep 2015 22:41:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B4=E6=96=B02.0=E6=94=B9=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/chapter2/01_The_Basics.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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" ``` From 3e6d27f20cb242359d4a227e5103b12d9dd5430d Mon Sep 17 00:00:00 2001 From: sunorry Date: Sat, 26 Sep 2015 00:34:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/chapter2/03_Strings_and_Characters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"