From 31b1da909ed3938024fe6d1e01c6f714b4649161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E6=9D=B0?= Date: Mon, 2 Nov 2015 10:25:11 +0800 Subject: [PATCH] add 2.1 guys --- source/chapter2/01_The_Basics.md | 1 + source/chapter2/03_Strings_and_Characters.md | 3 +- source/chapter2/05_Control_Flow.md | 1 + source/chapter2/06_Functions.md | 1 + source/chapter2/07_Closures.md | 2 +- source/chapter2/08_Enumerations.md | 1 + source/chapter2/10_Properties.md | 13 ++--- source/chapter2/14_Initialization.md | 1 + .../16_Automatic_Reference_Counting.md | 47 ++++++++++--------- source/chapter2/18_Error_Handling.md | 9 ++-- source/chapter2/22_Protocols.md | 4 +- source/chapter2/24_Access_Control.md | 1 + source/chapter3/02_Lexical_Structure.md | 3 ++ source/chapter3/03_Types.md | 3 ++ source/chapter3/04_Expressions.md | 3 ++ source/chapter3/05_Declarations.md | 19 ++++---- source/chapter3/06_Attributes.md | 13 +++-- source/chapter3/07_Patterns.md | 10 ++-- 18 files changed, 79 insertions(+), 56 deletions(-) diff --git a/source/chapter2/01_The_Basics.md b/source/chapter2/01_The_Basics.md index aa6c1a34..442413e5 100755 --- a/source/chapter2/01_The_Basics.md +++ b/source/chapter2/01_The_Basics.md @@ -9,6 +9,7 @@ > 翻译+校对:[xtymichael](https://github.com/xtymichael) > 2.1 +> 翻译:[Prayer](https://github.com/futantan) > 校对:[shanks](http://codebuild.me) 本页包含内容: diff --git a/source/chapter2/03_Strings_and_Characters.md b/source/chapter2/03_Strings_and_Characters.md index 47db7355..b0c123f3 100755 --- a/source/chapter2/03_Strings_and_Characters.md +++ b/source/chapter2/03_Strings_and_Characters.md @@ -8,7 +8,8 @@ > 2.0 > 翻译+校对:[DianQK](https://github.com/DianQK) -> 2.1 +> 2.1 +> 翻译:[DianQK](https://github.com/DianQK) > 校对:[shanks](http://codebuild.me) 本页包含内容: diff --git a/source/chapter2/05_Control_Flow.md b/source/chapter2/05_Control_Flow.md index 5eae98d6..b056ce89 100755 --- a/source/chapter2/05_Control_Flow.md +++ b/source/chapter2/05_Control_Flow.md @@ -9,6 +9,7 @@ > 翻译+校对:[JackAlan](https://github.com/AlanMelody) > 2.1 +> 翻译:[Prayer](https://github.com/futantan) > 校对:[shanks](http://codebuild.me) 本页包含内容: diff --git a/source/chapter2/06_Functions.md b/source/chapter2/06_Functions.md index fc34bf05..93c382ca 100755 --- a/source/chapter2/06_Functions.md +++ b/source/chapter2/06_Functions.md @@ -9,6 +9,7 @@ > 翻译+校对:[dreamkidd](https://github.com/dreamkidd) > 2.1 +> 翻译:[DianQK](https://github.com/DianQK) > 定稿:[shanks](http://codebuild.me) 本页包含内容: diff --git a/source/chapter2/07_Closures.md b/source/chapter2/07_Closures.md index 823f438a..da7153ab 100755 --- a/source/chapter2/07_Closures.md +++ b/source/chapter2/07_Closures.md @@ -9,7 +9,7 @@ > 翻译+校对:[100mango](https://github.com/100mango) > 2.1 -> 翻译:[magicdict](https://github.com/magicdict) +> 翻译:[100mango](https://github.com/100mango), [magicdict](https://github.com/magicdict) > 校对:[shanks](http://codebuild.me) 本页包含内容: diff --git a/source/chapter2/08_Enumerations.md b/source/chapter2/08_Enumerations.md index 6305d85a..2d19bdf1 100755 --- a/source/chapter2/08_Enumerations.md +++ b/source/chapter2/08_Enumerations.md @@ -9,6 +9,7 @@ > 翻译+校对:[futantan](https://github.com/futantan) > 2.1 +> 翻译:[Channe](https://github.com/Channe) > 校对:[shanks](http://codebuild.me) 本页内容包含: diff --git a/source/chapter2/10_Properties.md b/source/chapter2/10_Properties.md index 37b7176e..dafa72d0 100755 --- a/source/chapter2/10_Properties.md +++ b/source/chapter2/10_Properties.md @@ -1,14 +1,15 @@ # 属性 (Properties) ---- - +--- + > 1.0 > 翻译:[shinyzhu](https://github.com/shinyzhu) > 校对:[pp-prog](https://github.com/pp-prog) [yangsiy](https://github.com/yangsiy) > 2.0 -> 翻译+校对:[yangsiy](https://github.com/yangsiy) - -> 2.1 +> 翻译+校对:[yangsiy](https://github.com/yangsiy) + +> 2.1 +> 翻译:[buginux](https://github.com/buginux) > 校对:[shanks](http://codebuild.me),2015-10-29 本页包含内容: @@ -308,7 +309,7 @@ stepCounter.totalSteps = 896 > 注意: > 跟实例的存储属性不同,必须给存储型类型属性指定默认值,因为类型本身无法在初始化过程中使用构造器给类型属性赋值。 -> 存储型类型属性是延迟初始化的(lazily initialized),它们只有在第一次被访问的时候才会被初始化。即使它们被多个线程同时访问,系统也保证只会对其进行初始化一次,并且不需要对其使用 `lazy` 修饰符。 +> 存储型类型属性是延迟初始化的(lazily initialized),它们只有在第一次被访问的时候才会被初始化。即使它们被多个线程同时访问,系统也保证只会对其进行初始化一次,并且不需要对其使用 `lazy` 修饰符。 ###类型属性语法 diff --git a/source/chapter2/14_Initialization.md b/source/chapter2/14_Initialization.md index 5881874b..c1ece156 100755 --- a/source/chapter2/14_Initialization.md +++ b/source/chapter2/14_Initialization.md @@ -9,6 +9,7 @@ > 翻译+校对:[chenmingbiao](https://github.com/chenmingbiao) > 2.1 +> 翻译:[Channe](https://github.com/Channe) > 校对:[shanks](http://codebuild.me),2015-10-30 本页包含内容: diff --git a/source/chapter2/16_Automatic_Reference_Counting.md b/source/chapter2/16_Automatic_Reference_Counting.md index 4ef6d3fe..0881d76b 100755 --- a/source/chapter2/16_Automatic_Reference_Counting.md +++ b/source/chapter2/16_Automatic_Reference_Counting.md @@ -6,9 +6,10 @@ > 校对:[Hawstein](https://github.com/Hawstein) > 2.0 -> 翻译+校对:[Channe](https://github.com/Channe) - -> 2.1 +> 翻译+校对:[Channe](https://github.com/Channe) + +> 2.1 +> 翻译:[Channe](https://github.com/Channe) > 校对:[shanks](http://codebuild.me),2015-10-31 本页包含内容: @@ -189,7 +190,7 @@ Swift 提供了两种办法用来解决你在使用类的属性时所遇到的 弱引用和无主引用允许循环引用中的一个实例引用另外一个实例而不保持强引用。这样实例能够互相引用而不产生循环强引用。 对于生命周期中会变为`nil`的实例使用弱引用。相反地,对于初始化赋值后再也不会被赋值为`nil`的实例,使用无主引用。 - + ### 弱引用 @@ -264,9 +265,9 @@ unit4A = nil ``` 上面的两段代码展示了变量`john`和`unit4A`在被赋值为`nil`后,`Person`实例和`Apartment`实例的析构函数都打印出“销毁”的信息。这证明了引用循环被打破了。 - - >注意: - 在使用垃圾收集的系统里,弱指针有时用来实现简单的缓冲机制,因为没有强引用的对象只会在内存压力触发垃圾收集时才被销毁。但是在 ARC 中,一旦值的最后一个强引用被删除,就会被立即销毁,这导致弱引用并不适合上面的用途。 + + >注意: + 在使用垃圾收集的系统里,弱指针有时用来实现简单的缓冲机制,因为没有强引用的对象只会在内存压力触发垃圾收集时才被销毁。但是在 ARC 中,一旦值的最后一个强引用被删除,就会被立即销毁,这导致弱引用并不适合上面的用途。 ### 无主引用 @@ -448,18 +449,18 @@ class HTMLElement { 默认情况下,闭包赋值给了`asHTML`属性,这个闭包返回一个代表 HTML 标签的字符串。如果`text`值存在,该标签就包含可选值`text`;如果`text`不存在,该标签就不包含文本。对于段落元素,根据`text`是`"some text"`还是`nil`,闭包会返回"`

some text

`"或者"`

`"。 可以像实例方法那样去命名、使用`asHTML`属性。然而,由于`asHTML`是闭包而不是实例方法,如果你想改变特定元素的 HTML 处理的话,可以用自定义的闭包来取代默认值。 - -例如,可以将一个闭包赋值给`asHTML`属性,这个闭包能在文本属性是 nil 时用默认文本,这是为了避免返回一个空的 `HTML` 标签: - -```swift -let heading = HTMLElement(name: "h1") -let defaultText = "some default text" -heading.asHTML = { - return "<\(heading.name)>\(heading.text ?? defaultText)" -} -print(heading.asHTML()) -// prints "

some default text

" -``` + +例如,可以将一个闭包赋值给`asHTML`属性,这个闭包能在文本属性是 nil 时用默认文本,这是为了避免返回一个空的 `HTML` 标签: + +```swift +let heading = HTMLElement(name: "h1") +let defaultText = "some default text" +heading.asHTML = { + return "<\(heading.name)>\(heading.text ?? defaultText)" +} +print(heading.asHTML()) +// prints "

some default text

" +``` > 注意: `asHTML`声明为`lazy`属性,因为只有当元素确实需要处理为HTML输出的字符串时,才需要使用`asHTML`。也就是说,在默认的闭包中可以使用`self`,因为只有当初始化完成以及`self`确实存在后,才能访问`lazy`属性。 @@ -501,7 +502,7 @@ paragraph = nil >注意: Swift 有如下要求:只要在闭包内使用`self`的成员,就要用`self.someProperty`或者`self.someMethod()`(而不只是`someProperty`或`someMethod()`)。这提醒你可能会一不小心就捕获了`self`。 - + ###定义捕获列表 @@ -582,7 +583,7 @@ print(paragraph!.asHTML()) ```swift paragraph = nil // prints "p is being deinitialized" -``` - -For more information about capture lists, see Capture Lists. +``` + +For more information about capture lists, see Capture Lists. 你可以查看[捕获列表](../chapter3/04_Expressions.html)章节,获取更多关于捕获列表的信息 diff --git a/source/chapter2/18_Error_Handling.md b/source/chapter2/18_Error_Handling.md index 9fbd27ab..196ed928 100755 --- a/source/chapter2/18_Error_Handling.md +++ b/source/chapter2/18_Error_Handling.md @@ -3,13 +3,12 @@ > 2.1 > 翻译+校对:[lyojo](https://github.com/lyojo) [ray16897188](https://github.com/ray16897188) 2015-10-23 +> 校对:[shanks](http://codebuild.me) 2015-10-24 -> 定稿:[shanks](http://codebuild.me) 2015-10-24 +本页包含内容: -本页包含内容: - -- [表示并抛出错误](#representing_and_throwing_errors) -- [处理错误](#handling_errors) +- [表示并抛出错误](#representing_and_throwing_errors) +- [处理错误](#handling_errors) - [指定清理操作](#specifying_cleanup_actions) *错误处理(Error handling)*是响应错误以及从错误中恢复的过程。swift提供了在运行对可恢复错误抛出,捕获,传送和操作的高级支持。 diff --git a/source/chapter2/22_Protocols.md b/source/chapter2/22_Protocols.md index 6d4aa174..d6bfd573 100644 --- a/source/chapter2/22_Protocols.md +++ b/source/chapter2/22_Protocols.md @@ -6,10 +6,10 @@ > 校对:[dabing1022](https://github.com/dabing1022) > 2.0 -> 翻译:[futantan](https://github.com/futantan) -> 校对:[小铁匠Linus](https://github.com/kevin833752) +> 翻译+校对:[futantan](https://github.com/futantan) > 2.1 +> 翻译:[小铁匠Linus](https://github.com/kevin833752) > 校对:[shanks](http://codebuild.me),2015-11-01 本页包含内容: diff --git a/source/chapter2/24_Access_Control.md b/source/chapter2/24_Access_Control.md index 1d9c90f9..70d3e126 100644 --- a/source/chapter2/24_Access_Control.md +++ b/source/chapter2/24_Access_Control.md @@ -9,6 +9,7 @@ > 翻译+校对:[mmoaay](https://github.com/mmoaay) > 2.1 +> 翻译:[Prayer](https://github.com/futantan) > 校对:[shanks](http://codebuild.me),2015-11-01 本页内容包括: diff --git a/source/chapter3/02_Lexical_Structure.md b/source/chapter3/02_Lexical_Structure.md index a8799711..83ea50f8 100755 --- a/source/chapter3/02_Lexical_Structure.md +++ b/source/chapter3/02_Lexical_Structure.md @@ -8,6 +8,9 @@ > 2.0 > 翻译+校对:[buginux](https://github.com/buginux) +> 2.1 +> 翻译:[mmoaay](https://github.com/mmoaay) + 本页包含内容: diff --git a/source/chapter3/03_Types.md b/source/chapter3/03_Types.md index 87cadba5..feb2cfc1 100644 --- a/source/chapter3/03_Types.md +++ b/source/chapter3/03_Types.md @@ -8,6 +8,9 @@ > 2.0 > 翻译+校对:[EudeMorgen](https://github.com/EudeMorgen) +> 2.1 +> 翻译:[mmoaay](https://github.com/mmoaay) + 本页包含内容: - [类型注解(Type Annotation)](#type_annotation) diff --git a/source/chapter3/04_Expressions.md b/source/chapter3/04_Expressions.md index 801fde0c..9cc09211 100644 --- a/source/chapter3/04_Expressions.md +++ b/source/chapter3/04_Expressions.md @@ -8,6 +8,9 @@ > 2.0 > 翻译+校对:[EudeMorgen](https://github.com/EudeMorgen) +> 2.1 +> 翻译:[mmoaay](https://github.com/mmoaay) + 本页包含内容: - [前缀表达式(Prefix Expressions)](#prefix_expressions) diff --git a/source/chapter3/05_Declarations.md b/source/chapter3/05_Declarations.md index 5ad0a93a..81ba0d4c 100755 --- a/source/chapter3/05_Declarations.md +++ b/source/chapter3/05_Declarations.md @@ -8,10 +8,11 @@ > 2.0 > 翻译+校对:[Lenhoon](https://github.com/Lenhoon), -> [BridgeQ](https://github.com/WXGBridgeQ) - -> 2.1 -> 翻译+校队:[shanks](http://codebuild.me) +> [BridgeQ](https://github.com/WXGBridgeQ) + +> 2.1 +> 翻译:[mmoaay](https://github.com/mmoaay), [shanks](http://codebuild.me) +> 校队:[shanks](http://codebuild.me) 本页包含内容: @@ -327,8 +328,8 @@ func f(x x: Int, withY y: Int, _z: Int) -> Int{ return x + y + z } f(x: 1, withY: 2, 3) // x和y是有标记的,z没有 ``` - - + + ###特殊类型的参数 @@ -520,11 +521,11 @@ let f = Number.Integer let evenInts: [Number] = [0, 2, 4, 6].map(f) ``` -获得更多关于关联值类型的信息和例子,请查看[关联值(Associated Values)](../chapter2/08_Enumerations.html#associated_values)一节。 - +获得更多关于关联值类型的信息和例子,请查看[关联值(Associated Values)](../chapter2/08_Enumerations.html#associated_values)一节。 + -### 间接的枚举 +### 间接的枚举 枚举有一个递归结构,就是说,枚举有着枚举类型自身实例的关联值的用例。然而,枚举类型的实例有值语义,意味着它们在内存中有着固定的位置。为了支持递归,编译器必需插入一个间接层。 diff --git a/source/chapter3/06_Attributes.md b/source/chapter3/06_Attributes.md index 21f5b989..2b7e71bb 100755 --- a/source/chapter3/06_Attributes.md +++ b/source/chapter3/06_Attributes.md @@ -6,7 +6,10 @@ > 校对:[numbbbbb](https://github.com/numbbbbb), [stanzhai](https://github.com/stanzhai) > 2.0 -> 翻译+校对:[KYawn](https://github.com/KYawn),[小铁匠Linus](https://github.com/kevin833752) +> 翻译+校对:[KYawn](https://github.com/KYawn) + +> 2.1 +> 翻译:[小铁匠Linus](https://github.com/kevin833752) 本页内容包括: @@ -70,9 +73,9 @@ // First release protocol MyProtocol { // protocol definition -} -``` - +} +``` + ```swift // Subsequent release renames MyProtocol protocol MyRenamedProtocol { @@ -89,7 +92,7 @@ typealias MyProtocol = MyRenamedProtocol @available(`platform name` `version number`, *) -`available`特性的简写语法可以简明地表达出多个平台的可用性。尽管这两种形式在功能上是相同的,但请尽可能地使用简明语法形式。 +`available`特性的简写语法可以简明地表达出多个平台的可用性。尽管这两种形式在功能上是相同的,但请尽可能地使用简明语法形式。 ```swift @available(iOS 8.0, OSX 10.10, *) diff --git a/source/chapter3/07_Patterns.md b/source/chapter3/07_Patterns.md index d9aa54c2..c5cc97d2 100755 --- a/source/chapter3/07_Patterns.md +++ b/source/chapter3/07_Patterns.md @@ -1,13 +1,15 @@ # 模式(Patterns) ------------------ - +----------------- + > 1.0 > 翻译:[honghaoz](https://github.com/honghaoz) > 校对:[numbbbbb](https://github.com/numbbbbb), [stanzhai](https://github.com/stanzhai) > 2.0 -> 翻译+校对:[ray16897188](https://github.com/ray16897188), -> [BridgeQ](https://github.com/WXGBridgeQ) +> 翻译+校对:[ray16897188](https://github.com/ray16897188), + +> 2.1 +> 翻译:[BridgeQ](https://github.com/WXGBridgeQ) 本页内容包括: