From 8036fbd6e153148b9bf7166eba274e0a19a7653a Mon Sep 17 00:00:00 2001 From: Yongzheng Lai Date: Wed, 5 Aug 2015 17:24:03 +0800 Subject: [PATCH 1/3] Update 01_The_Basics.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、fix toInt issue 2、output issue 3、missing unwrapping `!` --- source/chapter2/01_The_Basics.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/chapter2/01_The_Basics.md b/source/chapter2/01_The_Basics.md index dce1b483..0e04b550 100755 --- a/source/chapter2/01_The_Basics.md +++ b/source/chapter2/01_The_Basics.md @@ -557,7 +557,7 @@ C 和 Objective-C 中并没有可选类型这个概念。最接近的是 Objecti ```swift let possibleNumber = "123" -let convertedNumber = Int(possibleNumber) +let convertedNumber = possibleNumber.toInt() // convertedNumber 被推测为类型 "Int?", 或者类型 "optional Int" ``` @@ -599,15 +599,15 @@ Swift 的`nil`和 Objective-C 中的`nil`并不一样。在 Objective-C 中,`n if convertedNumber != nil { print("convertedNumber contains some integer value.") } -// 输出 "转换的数字包含整数值。" +// 输出 "convertedNumber contains some integer value." ``` 当你确定可选类型确实包含值之后,你可以在可选的名字后面加一个感叹号(`!`)来获取值。这个惊叹号表示“我知道这个可选有值,请使用它。”这被称为可选值的_强制解析(forced unwrapping): ```swift if convertedNumber != nil { - print("convertedNumber has an integer value of \(convertedNumber).") + print("convertedNumber has an integer value of \(convertedNumber!).") } -// 输出 "转换的数字有整数值123。" +// 输出 "convertedNumber has an integer value of 123." ``` 更多关于`if`语句的内容,请参考[控制流](05_Control_Flow.html)。 From 2e5a211a89447797f8aec234740e86aee4c8e646 Mon Sep 17 00:00:00 2001 From: Yongzheng Lai Date: Wed, 5 Aug 2015 17:42:28 +0800 Subject: [PATCH 2/3] Update 01_The_Basics.md missing type and equal `=` --- source/chapter2/01_The_Basics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/chapter2/01_The_Basics.md b/source/chapter2/01_The_Basics.md index 0e04b550..4c866bc0 100755 --- a/source/chapter2/01_The_Basics.md +++ b/source/chapter2/01_The_Basics.md @@ -670,7 +670,7 @@ if let constantName = someOptional, anotherConstantName = someOtherOptional { ```swift let possibleString: String? = "An optional string." -let forcedString: possibleString! // 需要惊叹号来获取值 +let forcedString:String = possibleString! // 需要惊叹号来获取值 let assumedString: String! = "An implicitly unwrapped optional string." let implicitString: String = assumedString // 不需要感叹号 From cf29167b64cc3b34fec01fd56560e7f2535a9cb9 Mon Sep 17 00:00:00 2001 From: Yongzheng Lai Date: Wed, 5 Aug 2015 17:43:43 +0800 Subject: [PATCH 3/3] Update 01_The_Basics.md adding space --- source/chapter2/01_The_Basics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/chapter2/01_The_Basics.md b/source/chapter2/01_The_Basics.md index 4c866bc0..4138b68c 100755 --- a/source/chapter2/01_The_Basics.md +++ b/source/chapter2/01_The_Basics.md @@ -670,7 +670,7 @@ if let constantName = someOptional, anotherConstantName = someOtherOptional { ```swift let possibleString: String? = "An optional string." -let forcedString:String = possibleString! // 需要惊叹号来获取值 +let forcedString: String = possibleString! // 需要惊叹号来获取值 let assumedString: String! = "An implicitly unwrapped optional string." let implicitString: String = assumedString // 不需要感叹号