diff --git a/chapter1/01_swift.html b/chapter1/01_swift.html index 58df6e7a..2334ea26 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 fbac3e1b..e77383a4 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 923e60c6..906845e3 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 ccff32e6..e71da0ab 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 b0d007c0..4ba22dbf 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 0279259d..7d277189 100644 --- a/chapter2/03_Strings_and_Characters.html +++ b/chapter2/03_Strings_and_Characters.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:wh1100717
@@ -794,7 +794,7 @@ for scene in romeoAndJuliet { println("There are \(act1SceneCount) scenes in Act 1") // 打印输出:"There are 5 scenes in Act 1"相似地,您可以用
-hasSuffix方法来计算发生在不同地方的场景数:“var mansionCount = 0 +var mansionCount = 0 var cellCount = 0 for scene in romeoAndJuliet { if scene.hasSuffix("Capulet's mansion") { diff --git a/chapter2/04_Collection_Types.html b/chapter2/04_Collection_Types.html index 1af4f7f9..8e5b384a 100644 --- a/chapter2/04_Collection_Types.html +++ b/chapter2/04_Collection_Types.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:zqp
@@ -709,7 +709,7 @@创建并且构造一个数组
我们可以使用构造语法来创建一个由特定数据类型构成的空数组:
var someInts = Int[]() -println("someInts is of type Int[] with \(someInts。count) items。") +println("someInts is of type Int[] with \(someInts.count) items。") // 打印 "someInts is of type Int[] with 0 items。"(someInts是0数据项的Int[]数组)注意
someInts被设置为一个Int[]构造函数的输出所以它的变量类型被定义为Int[]。除此之外,如果代码上下文中提供了类型信息, 例如一个函数参数或者一个已经定义好类型的常量或者变量,我们可以使用空数组语句创建一个空数组,它的写法很简单:
@@ -765,14 +765,14 @@ someInts = [][](一对空方括号):if let oldValue = airports.updateValue("Dublin Internation", forKey: "DUB") { println("The old value for DUB was \(oldValue).") } -// 输出 "The old value for DUB was Dublin."(dub原值是dublin) +// 输出 "The old value for DUB was Dublin."(DUB原值是dublin)我们也可以使用下标语法来在字典中检索特定键对应的值。由于使用一个没有值的键这种情况是有可能发生的,可选类型返回这个键存在的相关值,否则就返回
nil:if let airportName = airports["DUB"] { println("The name of the airport is \(airportName).") } else { println("That airport is not in the airports dictionary.") } -// 打印 "The name of the airport is Dublin INTernation."(机场的名字是都柏林国际) +// 打印 "The name of the airport is Dublin Internation."(机场的名字是都柏林国际)我们还可以使用下标语法来通过给某个键的对应值赋值为
nil来从字典里移除一个键值对:airports["APL"] = "Apple Internation" // "Apple Internation"不是真的 APL机场, 删除它 @@ -789,20 +789,20 @@ airports["APL"] = nil字典遍历
我们可以使用
for-in循环来遍历某个字典中的键值对。每一个字典中的数据项都由(key, value)元组形式返回,并且我们可以使用暂时性常量或者变量来分解这些元组:for (airportCode, airportName) in airports { - prINTln("\(airportCode): \(airportName)") + println("\(airportCode): \(airportName)") } // TYO: Tokyo // LHR: London Heathrow
for-in循环请参见For 循环。我们也可以通过访问他的
keys或者values属性(都是可遍历集合)检索一个字典的键或者值:for airportCode in airports.keys { - prINTln("Airport code: \(airportCode)") + println("Airport code: \(airportCode)") } // Airport code: TYO // Airport code: LHR for airportName in airports.values { - prINTln("Airport name: \(airportName)") + println("Airport name: \(airportName)") } // Airport name: Tokyo // Airport name: London Heathrow @@ -835,7 +835,7 @@ namesOfIntegers = [:]集合的可变性
数组和字典都是在单个集合中存储可变值。如果我们创建一个数组或者字典并且把它分配成一个变量,这个集合将会是可变的。这意味着我们可以在创建之后添加更多或移除已存在的数据项来改变这个集合的大小。与此相反,如果我们把数组或字典分配成常量,那么他就是不可变的,它的大小不能被改变。
对字典来说,不可变性也意味着我们不能替换其中任何现有键所对应的值。不可变字典的内容在被首次设定之后不能更改。 -不可变行对数组来说有一点不同,当然我们不能试着改变任何不可变数组的大小,但是我们·可以重新设定相对现存索引所对应的值。这使得 Swift 数组在大小被固定的时候依然可以做的很棒。
+不可变性对数组来说有一点不同,当然我们不能试着改变任何不可变数组的大小,但是我们可以重新设定相对现存索引所对应的值。这使得 Swift 数组在大小被固定的时候依然可以做的很棒。Swift 数组的可变性行为同时影响了数组实例如何被分配和修改,想获取更多信息,请参见集合在赋值和复制中的行为。
注意:
diff --git a/chapter2/05_Control_Flow.html b/chapter2/05_Control_Flow.html index 9d26b549..dfc89750 100644 --- a/chapter2/05_Control_Flow.html +++ b/chapter2/05_Control_Flow.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:vclwei, coverxit, NicePiao
@@ -643,7 +643,7 @@ for _ in 1...power { println("\(base) to the power of \(power) is \(answer)") // 输出 "3 to the power of 10 is 59049" -这个例子计算 base 这个数的 power 次幂(本例中,是
+3的10次幂),从1(3的0次幂)开始做3的乘法, 进行10次,使用0到9的半闭区间循环。这个计算并不需要知道每一次循环中计数器具体的值,只需要执行了正确的循环次数即可。下划线符号_(替代循环中的变量)能够忽略具体的值,并且不提供循环遍历时对值的访问。这个例子计算 base 这个数的 power 次幂(本例中,是
3的10次幂),从1(3的0次幂)开始做3的乘法, 进行10次,使用1到10的半闭区间循环。这个计算并不需要知道每一次循环中计数器具体的值,只需要执行了正确的循环次数即可。下划线符号_(替代循环中的变量)能够忽略具体的值,并且不提供循环遍历时对值的访问。使用
for-in遍历一个数组所有元素:let names = ["Anna", "Alex", "Brian", "Jack"] for name in names { diff --git a/chapter2/06_Functions.html b/chapter2/06_Functions.html index b649da66..1eb45c63 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 824a3a0c..3801f1e5 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 9e0c6e26..a745f8f6 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 67923931..1f2ce5f5 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 5489c138..c804a26d 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 1a804a54..19afdf5c 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 8d74cf00..582d55e3 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 f0f1e329..99c85c44 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 87edd4c5..4eeefdab 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 5b1fab76..fa49e965 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 2700f26a..6b345ccb 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 168f9bcc..bf302632 100644 --- a/chapter2/17_Optional_Chaining.html +++ b/chapter2/17_Optional_Chaining.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:Jasonbroker
diff --git a/chapter2/18_Type_Casting.html b/chapter2/18_Type_Casting.html index 08b6305b..e0a23fff 100644 --- a/chapter2/18_Type_Casting.html +++ b/chapter2/18_Type_Casting.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:xiehurricane
diff --git a/chapter2/19_Nested_Types.html b/chapter2/19_Nested_Types.html index d84eb067..5ff30246 100644 --- a/chapter2/19_Nested_Types.html +++ b/chapter2/19_Nested_Types.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ 翻译:Lin-H
diff --git a/chapter2/20_Extensions.html b/chapter2/20_Extensions.html index 9ee4a2e6..28628f04 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 31d9b3c3..a4eba122 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 f752efa8..454adce0 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 5dd6c804..7d8421bf 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 0f9a897b..a1eeafea 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 5185e15f..2976b72f 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 4c52fc5b..906760bb 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 b1f9a783..1ff3c409 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 2932814b..a43fa552 100644 --- a/chapter3/04_Expressions.html +++ b/chapter3/04_Expressions.html @@ -46,7 +46,7 @@ -+@@ -587,7 +587,7 @@-+ +翻译:sg552
@@ -597,13 +597,13 @@
本页包含内容:
-
- [前缀表达式(Prefix Expressions)]
-- [二元表达式(Binary Expressions)]
-- [赋值表达式(Assignment Operator)]
-- [三元条件运算符(Ternary Conditional Operator)]
-- [类型转换运算符(Type-Casting Operators)]
-- [主要表达式(Primary Expressions)]
-- [后缀表达式(Postfix Expressions)]
+- 前缀表达式(Prefix Expressions)
+- 二元表达式(Binary Expressions)
+- 赋值表达式(Assignment Operator)
+- 三元条件运算符(Ternary Conditional Operator)
+- 类型转换运算符(Type-Casting Operators)
+- 主要表达式(Primary Expressions)
+- 后缀表达式(Postfix Expressions)
Swift 中存在四种表达式: 前缀(prefix)表达式,二元(binary)表达式,主要(primary)表达式和后缀(postfix)表达式。表达式可以返回一个值,以及运行某些逻辑(causes a side effect)。
前缀表达式和二元表达式就是对某些表达式使用各种运算符(operators)。 主要表达式是最短小的表达式,它提供了获取(变量的)值的一种途径。 后缀表达式则允许你建立复杂的表达式,例如配合函数调用和成员访问。 每种表达式都在下面有详细论述~
@@ -612,6 +612,7 @@expression → prefix-expressionbinary-expressions(opt) expression-list → expression| expression,expression-list
前缀表达式(Prefix Expressions)
前缀表达式由 前缀符号和表达式组成。(这个前缀符号只能接收一个参数)
Swift 标准库支持如下的前缀操作符:
@@ -631,6 +632,7 @@ prefix-expression → in-out-expression in-out-expression → &identifier +二元表达式(Binary Expressions)
二元表达式由 "左边参数" + "二元运算符" + "右边参数" 组成, 它有如下的形式:
@@ -740,6 +742,7 @@ binary-expression → type-casting-operator binary-expressions → binary-expressionbinary-expressions(opt) +
left-hand argumentoperatorright-hand argument赋值表达式(Assignment Operator)
The assigment operator sets a new value for a given expression. It has the following form: 赋值表达式会对某个给定的表达式赋值。 它有如下的形式;
@@ -753,6 +756,7 @@赋值表达式的语法
assignment-operator → =
+三元条件运算符(Ternary Conditional Operator)
三元条件运算符 是根据条件来获取值。 形式如下:
`condition` ? `expression used if true` : `expression used if false` @@ -762,6 +766,7 @@三元条件表达式
+
conditional-operator→ ?expression:类型转换运算符(Type-Casting Operators)
有两种类型转换操作符: as 和 is. 它们有如下的形式:
`expression` as `type` @@ -800,6 +805,7 @@ let y2: SomeType = x // Type information from an annotation类型转换的语法
type-casting-operator → istype| as?(opt)type
+主要表达式(Primary Expressions)
主要表达式是最基本的表达式。 它们可以跟 前缀表达式,二元表达式,后缀表达式以及其他主要表达式组合使用。@@ -994,6 +1000,7 @@ x = .AnotherValue+通配符表达式的语法
wildcard-expression → _
后缀表达式(Postfix Expressions)
后缀表达式就是在某个表达式的后面加上 操作符。 严格的讲,每个主要表达式(primary expression)都是一个后缀表达式
Swift 标准库提供了下列后缀表达式:
diff --git a/chapter3/05_Declarations.html b/chapter3/05_Declarations.html index c736082e..6c8067cb 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 83fdd84a..63ee3949 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 872140f1..90452336 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 1664047e..4d351842 100644 --- a/chapter3/08_Generic_Parameters_and_Arguments.html +++ b/chapter3/08_Generic_Parameters_and_Arguments.html @@ -46,7 +46,7 @@ -