diff --git a/chapter1/01_swift.html b/chapter1/01_swift.html index 99ebf14e..18a7e16e 100644 --- a/chapter1/01_swift.html +++ b/chapter1/01_swift.html @@ -46,7 +46,7 @@ -
翻译:numbbbbb
diff --git a/chapter1/02_a_swift_tour.html b/chapter1/02_a_swift_tour.html index d4637e8a..12c5b84b 100644 --- a/chapter1/02_a_swift_tour.html +++ b/chapter1/02_a_swift_tour.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:numbbbbb diff --git a/chapter1/chapter1.html b/chapter1/chapter1.html index 1987b8d5..a6b4fdf7 100644 --- a/chapter1/chapter1.html +++ b/chapter1/chapter1.html @@ -46,7 +46,7 @@ -
+@@ -587,7 +587,7 @@-+ 欢迎使用 Swift
在本章中您将了解 Swift 的特性和开发历史,并对 Swift 有一个初步的了解。
diff --git a/chapter2/01_The_Basics.html b/chapter2/01_The_Basics.html index feadd798..8810740c 100644 --- a/chapter2/01_The_Basics.html +++ b/chapter2/01_The_Basics.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:numbbbbb, lyuka, JaySurplus
diff --git a/chapter2/02_Basic_Operators.html b/chapter2/02_Basic_Operators.html index c802502e..e3485168 100644 --- a/chapter2/02_Basic_Operators.html +++ b/chapter2/02_Basic_Operators.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:xielingwang
diff --git a/chapter2/03_Strings_and_Characters.html b/chapter2/03_Strings_and_Characters.html index 55c5d944..ea9177b1 100644 --- a/chapter2/03_Strings_and_Characters.html +++ b/chapter2/03_Strings_and_Characters.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:wh1100717
diff --git a/chapter2/04_Collection_Types.html b/chapter2/04_Collection_Types.html index 02bd6520..7b64f33b 100644 --- a/chapter2/04_Collection_Types.html +++ b/chapter2/04_Collection_Types.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:zqp
@@ -821,7 +821,7 @@ let airportNames = Array(airports.values)我们可以像数组一样使用构造语法创建一个空字典:
var namesOfIntegers = Dictionary<Int, String>() // namesOfIntegers 是一个空的 Dictionary<Int, String> -这个例子创建了一个
+Int, String类型的空字典来储存英语对整数的命名。他的键是Int型,值是String型。这个例子创建了一个
Int, String类型的空字典来储存英语对整数的命名。它的键是Int型,值是String型。如果上下文已经提供了信息类型,我们可以使用空字典字面语句来创建一个空字典,记作
[:](中括号中放一个冒号):namesOfIntegers[16] = "sixteen" // namesOfIntegers 现在包含一个键值对 diff --git a/chapter2/05_Control_Flow.html b/chapter2/05_Control_Flow.html index 50ace14e..780640e6 100644 --- a/chapter2/05_Control_Flow.html +++ b/chapter2/05_Control_Flow.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:vclwei, coverxit, NicePiao
diff --git a/chapter2/06_Functions.html b/chapter2/06_Functions.html index 64e7c149..818a9724 100644 --- a/chapter2/06_Functions.html +++ b/chapter2/06_Functions.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:honghaoz
diff --git a/chapter2/07_Closures.html b/chapter2/07_Closures.html index 19778b21..17373511 100644 --- a/chapter2/07_Closures.html +++ b/chapter2/07_Closures.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:wh1100717
diff --git a/chapter2/08_Enumerations.html b/chapter2/08_Enumerations.html index 776b4b85..b443497e 100644 --- a/chapter2/08_Enumerations.html +++ b/chapter2/08_Enumerations.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:yankuangshi
diff --git a/chapter2/09_Classes_and_Structures.html b/chapter2/09_Classes_and_Structures.html index 522f0535..5aa6625f 100644 --- a/chapter2/09_Classes_and_Structures.html +++ b/chapter2/09_Classes_and_Structures.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:JaySurplus
diff --git a/chapter2/10_Properties.html b/chapter2/10_Properties.html index 55cf76d0..36d45ff0 100644 --- a/chapter2/10_Properties.html +++ b/chapter2/10_Properties.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:shinyzhu
diff --git a/chapter2/11_Methods.html b/chapter2/11_Methods.html index 8032d98b..416d08bf 100644 --- a/chapter2/11_Methods.html +++ b/chapter2/11_Methods.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:pp-prog
diff --git a/chapter2/12_Subscripts.html b/chapter2/12_Subscripts.html index 3474b61e..b6d4af4e 100644 --- a/chapter2/12_Subscripts.html +++ b/chapter2/12_Subscripts.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:siemenliu
diff --git a/chapter2/13_Inheritance.html b/chapter2/13_Inheritance.html index 0e927b95..b913c241 100644 --- a/chapter2/13_Inheritance.html +++ b/chapter2/13_Inheritance.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:Hawstein
diff --git a/chapter2/14_Initialization.html b/chapter2/14_Initialization.html index 6c373904..ac040dc2 100644 --- a/chapter2/14_Initialization.html +++ b/chapter2/14_Initialization.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:lifedim
diff --git a/chapter2/15_Deinitialization.html b/chapter2/15_Deinitialization.html index 917d3a77..79d2778e 100644 --- a/chapter2/15_Deinitialization.html +++ b/chapter2/15_Deinitialization.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:bruce0505
diff --git a/chapter2/16_Automatic_Reference_Counting.html b/chapter2/16_Automatic_Reference_Counting.html index 21750390..0d7571f8 100644 --- a/chapter2/16_Automatic_Reference_Counting.html +++ b/chapter2/16_Automatic_Reference_Counting.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:TimothyYe
diff --git a/chapter2/17_Optional_Chaining.html b/chapter2/17_Optional_Chaining.html index efe44fc1..bd33cd6f 100644 --- a/chapter2/17_Optional_Chaining.html +++ b/chapter2/17_Optional_Chaining.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:Jasonbroker
@@ -603,16 +603,16 @@通过可选链调用方法 使用可选链调用子脚本 连接多层链接 -链接自判断返回值的方法 +链接可选返回值的方法 -可选链(Optional Chaining)是一种可以请求和调用属性、方法及子脚本的过程,它的自判断性体现于请求或调用的目标当前可能为空(
+nil)。如果自判断的目标有值,那么调用就会成功;相反,如果选择的目标为空(nil),则这种调用将返回空(nil)。多次请求或调用可以被链接在一起形成一个链,如果任何一个节点为空(nil)将导致整个链失效。可选链(Optional Chaining)是一种可以请求和调用属性、方法及子脚本的过程,它的可选性体现于请求或调用的目标当前可能为空(
nil)。如果可选的目标有值,那么调用就会成功;相反,如果选择的目标为空(nil),则这种调用将返回空(nil)。多次请求或调用可以被链接在一起形成一个链,如果任何一个节点为空(nil)将导致整个链失效。注意: -Swift 的自判断链和 Objective-C 中的消息为空有些相像,但是 Swift 可以使用在任意类型中,并且失败与否可以被检测到。
+Swift 的可选链和 Objective-C 中的消息为空有些相像,但是 Swift 可以使用在任意类型中,并且失败与否可以被检测到。可选链可替代强制解析
-通过在想调用的属性、方法、或子脚本的可选值(
+optional value)(非空)后面放一个问号,可以定义一个可选链。这一点很像在可选值后面放一个声明符号来强制拆得其封包内的值。他们的主要的区别在于当可选值为空时可选链即刻失败,然而一般的强制解析将会引发运行时错误。通过在想调用的属性、方法、或子脚本的可选值(
optional value)(非空)后面放一个问号,可以定义一个可选链。这一点很像在可选值后面放一个叹号来强制拆得其封包内的值。他们的主要的区别在于当可选值为空时可选链即刻失败,然而一般的强制解析将会引发运行时错误。为了反映可选链可以调用空(
nil),不论你调用的属性、方法、子脚本等返回的值是不是可选值,它的返回结果都是一个可选值。你可以利用这个返回值来检测你的可选链是否调用成功,有返回值即成功,返回nil则失败。调用可选链的返回结果与原本的返回结果具有相同的类型,但是原本的返回结果被包装成了一个可选值,当可选链调用成功时,一个应该返回
Int的属性将会返回Int?。下面几段代码将解释可选链和强制解析的不同。
@@ -624,8 +624,8 @@ Swift 的自判断链和 Objective-C 中的消息为空有些相像,但是 Swi class Residence { var numberOfRooms = 1 } --
Residence具有一个Int类型的numberOfRooms,其值为 1。Person具有一个自判断residence属性,它的类型是Residence?。如果你创建一个新的
+Person实例,它的residence属性由于是被定义为自判断型的,此属性将默认初始化为空:+
Residence具有一个Int类型的numberOfRooms,其值为 1。Person具有一个可选residence属性,它的类型是Residence?。如果你创建一个新的
Person实例,它的residence属性由于是被定义为可选型的,此属性将默认初始化为空:let john = Person()如果你想使用感叹号(
!)强制解析获得这个人residence属性numberOfRooms属性值,将会引发运行时错误,因为这时没有可以供解析的residence值。let roomCount = john.residence!.numberOfRooms @@ -638,9 +638,9 @@ class Residence { println("Unable to retrieve the number of rooms.") } // 打印 "Unable to retrieve the number of rooms. -这告诉 Swift 来链接自判断
-residence?属性,如果residence存在则取回numberOfRooms的值。因为这种尝试获得
-numberOfRooms的操作有可能失败,可选链会返回Int?类型值,或者称作“自判断Int”。当residence是空的时候(上例),选择Int将会为空,因此会出先无法访问numberOfRooms的情况。要注意的是,即使numberOfRooms是非自判断
+Int(Int?)时这一点也成立。只要是通过可选链的请求就意味着最后numberOfRooms总是返回一个Int?而不是Int。这告诉 Swift 来链接可选
+residence?属性,如果residence存在则取回numberOfRooms的值。因为这种尝试获得
+numberOfRooms的操作有可能失败,可选链会返回Int?类型值,或者称作“可选Int”。当residence是空的时候(上例),选择Int将会为空,因此会出先无法访问numberOfRooms的情况。要注意的是,即使numberOfRooms是非可选
Int(Int?)时这一点也成立。只要是通过可选链的请求就意味着最后numberOfRooms总是返回一个Int?而不是Int。你可以自己定义一个
Residence实例给john.residence,这样它就不再为空了:john.residence = Residence()@@ -675,13 +675,13 @@ class Residence {
john.residence现在有了实际存在的实例而不是nil了。如果你想使用和前面一样的可选链来获得numberOfRoooms,它将返回一个包含默认值 1 的Int?:因为
Residence存储了一个Room实例的数组,它的numberOfRooms属性值不是一个固定的存储值,而是通过计算而来的。numberOfRooms属性值是由返回rooms数组的count属性值得到的。为了能快速访问
rooms数组,Residence定义了一个只读的子脚本,通过插入数组的元素角标就可以成功调用。如果该角标存在,子脚本则将该元素返回。-
Residence中也提供了一个printNumberOfRooms的方法,即简单的打印房间个数。最后,
Residence定义了一个自判断属性叫address(address?)。Address类的属性将在后面定义。 +最后,
Residence定义了一个可选属性叫address(address?)。Address类的属性将在后面定义。 用于rooms数组的Room类是一个很简单的类,它只有一个name属性和一个设定room名的初始化器。class Room { let name: String init(name: String) { self.name = name } } -这个模型中的最终类叫做
+Address。它有三个自判断属性他们额类型是String?。前面两个自判断属性buildingName和buildingNumber作为地址的一部分,是定义某个建筑物的两种方式。第三个属性street,用于命名地址的街道名:这个模型中的最终类叫做
Address。它有三个类型是String?的可选属性。前面两个可选属性buildingName和buildingNumber作为地址的一部分,是定义某个建筑物的两种方式。第三个属性street,用于命名地址的街道名:class Address { var buildingName: String? var buildingNumber: String? @@ -717,7 +717,7 @@ if let roomCount = john.residence?.numberOfRooms { println(“The number of rooms is \(numberOfRooms)”) }这个方法没有返回值。但是,没有返回值类型的函数和方法有一个隐式的返回值类型
-Void(参见Function Without Return Values)。如果你利用可选链调用此方法,这个方法的返回值类型将是
+Void?,而不是Void,因为当通过可选链调用方法时返回值总是可选类型(optional type)。,即使是这个方法本是没有定义返回值,你也可以使用if语句来检查是否能成功调用printNumberOfRooms方法:如果方法通过可选链调用成功,printNumberOfRooms的隐式返回值将会是Void,如果没有成功,将返回nil:如果你利用可选链调用此方法,这个方法的返回值类型将是
Void?,而不是Void,因为当通过可选链调用方法时返回值总是可选类型(optional type)。即使这个方法本身没有定义返回值,你也可以使用if语句来检查是否能成功调用printNumberOfRooms方法:如果方法通过可选链调用成功,printNumberOfRooms的隐式返回值将会是Void,如果没有成功,将返回nil:if john.residence?.printNumberOfRooms() { println("It was possible to print the number of rooms.") } else { @@ -729,7 +729,7 @@ if let roomCount = john.residence?.numberOfRooms {你可以使用可选链来尝试从子脚本获取值并检查子脚本的调用是否成功,然而,你不能通过可选链来设置子代码。
注意: -当你使用可选链来获取子脚本的时候,你应该将问号放在子脚本括号的前面而不是后面。可选链的问号一般直接跟在自判断表达语句的后面。
+当你使用可选链来获取子脚本的时候,你应该将问号放在子脚本括号的前面而不是后面。可选链的问号一般直接跟在表达语句的后面。下面这个例子用在
Residence类中定义的子脚本来获取john.residence数组中第一个房间的名字。因为john.residence现在是nil,子脚本的调用失败了。if let firstRoomName = john.residence?[0].name { @@ -756,7 +756,7 @@ if let firstRoomName = john.residence?[0].name {你可以将多层可选链连接在一起,可以掘取模型内更下层的属性方法和子脚本。然而多层可选链不能再添加比已经返回的可选值更多的层。 也就是说:
如果你试图获得的类型不是可选类型,由于使用了可选链它将变成可选类型。 -如果你试图获得的类型已经是可选类型,由于可选链它也不会提高自判断性。
+如果你试图获得的类型已经是可选类型,由于可选链它也不会提高可选性。因此:
如果你试图通过可选链获得
@@ -781,10 +781,10 @@ if let johnsStreet = john.residence?.address?.street { println("Unable to retrieve the address.") } // 打印 "John's street name is Laurel Street."。 -Int值,不论使用了多少层链接返回的总是Int?。 相似的,如果你试图通过可选链获得Int?值,不论使用了多少层链接返回的总是Int?。值得注意的是,“
+!”符的在定义address实例时的使用(john.residence.address)。john.residence属性是一个可选类型,因此你需要在它获取address属性之前使用!解析以获得它的实际值。值得注意的是,“
-!”符号在给john.residence.address分配address实例时的使用。john.residence属性是一个可选类型,因此你需要在它获取address属性之前使用!解析以获得它的实际值。链接自判断返回值的方法
-前面的例子解释了如何通过可选链来获得可选类型属性值。你也可以通过调用返回可选类型值的方法并按需链接方法的返回值。
+链接可选返回值的方法
+前面的例子解释了如何通过可选链来获得可选类型属性值。你也可以通过可选链调用一个返回可选类型值的方法并按需链接该方法的返回值。
下面的例子通过可选链调用了
Address类中的buildingIdentifier方法。这个方法的返回值类型是String?。如上所述,这个方法在可选链调用后最终的返回值类型依然是String?:if let buildingIdentifier = john.residence?.address?.buildingIdentifier() { println("John's building identifier is \(buildingIdentifier).") diff --git a/chapter2/18_Type_Casting.html b/chapter2/18_Type_Casting.html index a58e5c86..5f5b52a5 100644 --- a/chapter2/18_Type_Casting.html +++ b/chapter2/18_Type_Casting.html @@ -46,7 +46,7 @@ -+@@ -587,24 +587,24 @@-+ -翻译:xiehurricane
校对:happyming
类型检查(Type Casting)
+类型转换(Type Casting)
本页包含内容:
类型检查是一种检查类实例的方式,并且或者也是让实例作为它的父类或者子类的一种方式。
类型检查在 Swift 中使用
-is和as操作符实现。这两个操作符提供了一种简单达意的方式去检查值的类型或者转换它的类型。你也可以用来检查一个类是否实现了某个协议,就像在 Protocols Checking for Protocol Conformance部分讲述的一样。
+你也可以用来检查一个类是否实现了某个协议,就像在 Checking for Protocol Conformance部分讲述的一样。
定义一个类层次作为例子
你可以将它用在类和子类的层次结构上,检查特定类实例的类型并且转换这个类实例的类型成为这个层次结构中的其他类型。这下面的三个代码段定义了一个类层次和一个包含了几个这些类实例的数组,作为类型检查的例子。
@@ -621,7 +621,7 @@ init(name: String, director: String) { self.director = director super.init(name: name) - } + } } class Song: MediaItem { @@ -634,17 +634,17 @@ class Song: MediaItem {最后一个代码段创建了一个数组常量
library,包含两个Movie实例和三个Song实例。library的类型是在它被初始化时根据它数组中所包含的内容推断来的。Swift 的类型检测器能够演绎出Movie和Song有共同的父类MediaItem,所以它推断出MediaItem[]类作为library的类型。let library = [ -Movie(name: "Casablanca", director: "Michael Curtiz"), -Song(name: "Blue Suede Shoes", artist: "Elvis Presley"), -Movie(name: "Citizen Kane", director: "Orson Welles"), -Song(name: "The One And Only", artist: "Chesney Hawkes"), -Song(name: "Never Gonna Give You Up", artist: "Rick Astley") + Movie(name: "Casablanca", director: "Michael Curtiz"), + Song(name: "Blue Suede Shoes", artist: "Elvis Presley"), + Movie(name: "Citizen Kane", director: "Orson Welles"), + Song(name: "The One And Only", artist: "Chesney Hawkes"), + Song(name: "Never Gonna Give You Up", artist: "Rick Astley") ] // the type of "library" is inferred to be MediaItem[]在幕后
library里存储的媒体项依然是Movie和Song类型的,但是,若你迭代它,取出的实例会是MediaItem类型的,而不是Movie和Song类型的。为了让它们作为它们本来的类型工作,你需要检查它们的类型或者向下转换它们的类型到其它类型,就像下面描述的一样。检查类型
-用类型检查操作符(
+is)来检查一个实例是否属于特定子类型。类型检查操作符返回true若实例属于那个子类型,若不属于返回false。用类型检查操作符(
is)来检查一个实例是否属于特定子类型。若实例属于那个子类型,类型检查操作符返回true,否则返回false。下面的例子定义了两个变量,
movieCount和songCount,用来计算数组library中Movie和Song类型的实例数量。var movieCount = 0 var songCount = 0 @@ -666,12 +666,12 @@ println("Media library contains \(movieCount) movies and \(songCount) songs Song检查item是否为Song类型的实例。在循环结束后,movieCount和songCount的值就是被找到属于各自的类型的实例数量。向下转型(Downcasting)
-某类型的一个常量或变量可能在幕后实际上属于一个子类。你可以相信,上面就是这种情况。你可以尝试向下转到它的子类型,用类型检查操作符(
-as)因为向下转型可能会失败,类型检查操作符带有两种不同形式。可选形式( optional form)
-as?返回一个你试图下转成的类型的可选值(optional value)。强制形式as把试图向下转型和强制解包(force-unwraps)结果作为一个混合动作。当你不确定下转可以成功时,用类型检查的可选形式(
-as?)。可选形式的类型检查总是返回一个可选值(optional value),并且若下转是不可能的,可选值将是nil。这使你能够检查下转是否成功。只有你可以确定下转一定会成功时,才使用强制形式。当你试图下转为一个不正确的类型时,强制形式的类型检查会触发一个运行时错误。
+某类型的一个常量或变量可能在幕后实际上属于一个子类。你可以相信,上面就是这种情况。你可以尝试向下转到它的子类型,用类型转换操作符(
+as)因为向下转型可能会失败,类型转型操作符带有两种不同形式。可选形式( optional form)
+as?返回一个你试图下转成的类型的可选值(optional value)。强制形式as把试图向下转型和强制解包(force-unwraps)结果作为一个混合动作。当你不确定向下转型可以成功时,用类型转换的可选形式(
+as?)。可选形式的类型转换总是返回一个可选值(optional value),并且若下转是不可能的,可选值将是nil。这使你能够检查向下转型是否成功。只有你可以确定向下转型一定会成功时,才使用强制形式。当你试图向下转型为一个不正确的类型时,强制形式的类型转换会触发一个运行时错误。
下面的例子,迭代了
-library里的每一个MediaItem,并打印出适当的描述。要这样做,item需要真正作为Movie或Song的类型来使用。不仅仅是作为MediaItem。为了能够使用Movie或Song的director或artist属性,这是必要的。在这个示例中,数组中的每一个
+item可能是Movie或Song。 事前你不知道每个item的真实类型,所以这里使用可选形式的类型检查 (as?)去检查循环里的每次下转。在这个示例中,数组中的每一个
item可能是Movie或Song。 事前你不知道每个item的真实类型,所以这里使用可选形式的类型转换 (as?)去检查循环里的每次下转。for item in library { if let movie = item as? Movie { println("Movie: '\(movie.name)', dir. \(movie.director)") @@ -688,16 +688,16 @@ println("Media library contains \(movieCount) movies and \(songCount) songs示例首先试图将
-item下转为Movie。因为item是一个MediaItem类型的实例,它可能是一个Movie;同样,它可能是一个Song,或者仅仅是基类MediaItem。因为不确定,as?形式在试图下转时将返还一个可选值。item as Movie的返回值是Movie?类型或 “optionalMovie”。当下转为
Movie应用在两个Song+当向下转型为
Movie应用在两个Song实例时将会失败。为了处理这种情况,上面的例子使用了可选绑定(optional binding)来检查可选Movie真的包含一个值(这个是为了判断下转是否成功。)可选绑定是这样写的“if let movie = item as? Movie”,可以这样解读:“尝试将
-item转为Movie类型。若成功,设置一个新的临时常量movie来存储返回的可选Movie”若下转成功,然后
+movie的属性将用于打印一个Movie实例的描述,包括它的导演的名字director。当Song被找到时,一个相近的原理被用来检测Song实例和打印它的描述。若向下转型成功,然后
movie的属性将用于打印一个Movie实例的描述,包括它的导演的名字director。当Song被找到时,一个相近的原理被用来检测Song实例和打印它的描述。-注意:
转换没有真的改变实例或它的值。潜在的根本的实例保持不变;只是简单地把它作为它被转换成的类来使用。
+
Any和AnyObject的类型检查
Any和AnyObject的类型转换Swift为不确定类型提供了两种特殊类型别名:
@@ -712,7 +712,7 @@ println("Media library contains \(movieCount) movies and \(songCount) songs
AnyObject可以代表任何class类型的实例。
AnyObject类型当需要在工作中使用 Cocoa APIs,它一般接收一个
-AnyObject[]类型的数组,或者说“一个任何对象类型的数组”。这是因为 Objective-C 没有明确的类型化数组。但是,你常常可以确定包含在仅从你知道的 API 信息提供的这样一个数组中的对象的类型。在这些情况下,你可以使用强制形式的类型检查(
+as)来下转在数组中的每一项到比AnyObject更明确的类型,不需要可选解析(optional unwrapping)。在这些情况下,你可以使用强制形式的类型转换(
as)来下转在数组中的每一项到比AnyObject更明确的类型,不需要可选解析(optional unwrapping)。下面的示例定义了一个
AnyObject[]类型的数组并填入三个Movie类型的实例:let someObjects: AnyObject[] = [ Movie(name: "2001: A Space Odyssey", director: "Stanley Kubrick"), @@ -780,7 +780,7 @@ things.append(Movie(name: "Ghostbusters", director: "Ivan Reitman。
diff --git a/chapter2/19_Nested_Types.html b/chapter2/19_Nested_Types.html index d0d4dcd9..5f1fd0e9 100644 --- a/chapter2/19_Nested_Types.html +++ b/chapter2/19_Nested_Types.html @@ -46,7 +46,7 @@ -注意:
-在一个switch语句的case中使用强制形式的类型检查操作符(as, 而不是 as?)来检查和转换到一个明确的类型。在 switch case 语句的内容中这种检查总是安全的。
+在一个switch语句的case中使用强制形式的类型转换操作符(as, 而不是 as?)来检查和转换到一个明确的类型。在 switch case 语句的内容中这种检查总是安全的。
+@@ -587,7 +587,7 @@-+ 翻译:Lin-H
diff --git a/chapter2/20_Extensions.html b/chapter2/20_Extensions.html index 82f334a2..7d1c4ed1 100644 --- a/chapter2/20_Extensions.html +++ b/chapter2/20_Extensions.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:lyuka
diff --git a/chapter2/21_Protocols.html b/chapter2/21_Protocols.html index 202fc6ee..a25334a3 100644 --- a/chapter2/21_Protocols.html +++ b/chapter2/21_Protocols.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:geek5nan
diff --git a/chapter2/22_Generics.html b/chapter2/22_Generics.html index 146f94a1..32677308 100644 --- a/chapter2/22_Generics.html +++ b/chapter2/22_Generics.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:takalard
diff --git a/chapter2/23_Advanced_Operators.html b/chapter2/23_Advanced_Operators.html index 53fbbe67..f652e97b 100644 --- a/chapter2/23_Advanced_Operators.html +++ b/chapter2/23_Advanced_Operators.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:xielingwang
diff --git a/chapter2/chapter2.html b/chapter2/chapter2.html index 5b5a13f5..af9c990c 100644 --- a/chapter2/chapter2.html +++ b/chapter2/chapter2.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ Swift 教程
本章介绍了 Swift 的各种特性及其使用方法,是全书的核心部分。
diff --git a/chapter3/01_About_the_Language_Reference.html b/chapter3/01_About_the_Language_Reference.html index b2d83b5e..6fb4ab69 100644 --- a/chapter3/01_About_the_Language_Reference.html +++ b/chapter3/01_About_the_Language_Reference.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:ChildhoodAndy
diff --git a/chapter3/02_Lexical_Structure.html b/chapter3/02_Lexical_Structure.html index 27bb3df9..b77d67c8 100644 --- a/chapter3/02_Lexical_Structure.html +++ b/chapter3/02_Lexical_Structure.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:superkam
diff --git a/chapter3/03_Types.html b/chapter3/03_Types.html index 6cbfd6cb..d94d3252 100644 --- a/chapter3/03_Types.html +++ b/chapter3/03_Types.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:lyuka
diff --git a/chapter3/04_Expressions.html b/chapter3/04_Expressions.html index e1e28e07..55b3b9b2 100644 --- a/chapter3/04_Expressions.html +++ b/chapter3/04_Expressions.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:sg552
diff --git a/chapter3/05_Declarations.html b/chapter3/05_Declarations.html index 98f3a82d..a2b48e48 100644 --- a/chapter3/05_Declarations.html +++ b/chapter3/05_Declarations.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:marsprince
diff --git a/chapter3/06_Attributes.html b/chapter3/06_Attributes.html index 76885a5d..7cfe8bee 100644 --- a/chapter3/06_Attributes.html +++ b/chapter3/06_Attributes.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:Hawstein
diff --git a/chapter3/07_Patterns.html b/chapter3/07_Patterns.html index 3803423f..88b141c0 100644 --- a/chapter3/07_Patterns.html +++ b/chapter3/07_Patterns.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:honghaoz
diff --git a/chapter3/08_Generic_Parameters_and_Arguments.html b/chapter3/08_Generic_Parameters_and_Arguments.html index c18d95c0..71e167b8 100644 --- a/chapter3/08_Generic_Parameters_and_Arguments.html +++ b/chapter3/08_Generic_Parameters_and_Arguments.html @@ -46,7 +46,7 @@ -+