add 2.1 guys
This commit is contained in:
@ -9,6 +9,7 @@
|
||||
> 翻译+校对:[xtymichael](https://github.com/xtymichael)
|
||||
|
||||
> 2.1
|
||||
> 翻译:[Prayer](https://github.com/futantan)
|
||||
> 校对:[shanks](http://codebuild.me)
|
||||
|
||||
本页包含内容:
|
||||
|
||||
@ -8,7 +8,8 @@
|
||||
> 2.0
|
||||
> 翻译+校对:[DianQK](https://github.com/DianQK)
|
||||
|
||||
> 2.1
|
||||
> 2.1
|
||||
> 翻译:[DianQK](https://github.com/DianQK)
|
||||
> 校对:[shanks](http://codebuild.me)
|
||||
|
||||
本页包含内容:
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
> 翻译+校对:[JackAlan](https://github.com/AlanMelody)
|
||||
|
||||
> 2.1
|
||||
> 翻译:[Prayer](https://github.com/futantan)
|
||||
> 校对:[shanks](http://codebuild.me)
|
||||
|
||||
本页包含内容:
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
> 翻译+校对:[dreamkidd](https://github.com/dreamkidd)
|
||||
|
||||
> 2.1
|
||||
> 翻译:[DianQK](https://github.com/DianQK)
|
||||
> 定稿:[shanks](http://codebuild.me)
|
||||
|
||||
本页包含内容:
|
||||
|
||||
@ -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)
|
||||
|
||||
本页包含内容:
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
> 翻译+校对:[futantan](https://github.com/futantan)
|
||||
|
||||
> 2.1
|
||||
> 翻译:[Channe](https://github.com/Channe)
|
||||
> 校对:[shanks](http://codebuild.me)
|
||||
|
||||
本页内容包含:
|
||||
|
||||
@ -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` 修饰符。
|
||||
|
||||
<a name="type_property_syntax"></a>
|
||||
###类型属性语法
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
> 翻译+校对:[chenmingbiao](https://github.com/chenmingbiao)
|
||||
|
||||
> 2.1
|
||||
> 翻译:[Channe](https://github.com/Channe)
|
||||
> 校对:[shanks](http://codebuild.me),2015-10-30
|
||||
|
||||
本页包含内容:
|
||||
|
||||
@ -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`的实例,使用无主引用。
|
||||
|
||||
|
||||
<a name="weak_references"></a>
|
||||
### 弱引用
|
||||
|
||||
@ -264,9 +265,9 @@ unit4A = nil
|
||||
```
|
||||
|
||||
上面的两段代码展示了变量`john`和`unit4A`在被赋值为`nil`后,`Person`实例和`Apartment`实例的析构函数都打印出“销毁”的信息。这证明了引用循环被打破了。
|
||||
|
||||
>注意:
|
||||
在使用垃圾收集的系统里,弱指针有时用来实现简单的缓冲机制,因为没有强引用的对象只会在内存压力触发垃圾收集时才被销毁。但是在 ARC 中,一旦值的最后一个强引用被删除,就会被立即销毁,这导致弱引用并不适合上面的用途。
|
||||
|
||||
>注意:
|
||||
在使用垃圾收集的系统里,弱指针有时用来实现简单的缓冲机制,因为没有强引用的对象只会在内存压力触发垃圾收集时才被销毁。但是在 ARC 中,一旦值的最后一个强引用被删除,就会被立即销毁,这导致弱引用并不适合上面的用途。
|
||||
|
||||
<a name="unowned_references"></a>
|
||||
### 无主引用
|
||||
@ -448,18 +449,18 @@ class HTMLElement {
|
||||
默认情况下,闭包赋值给了`asHTML`属性,这个闭包返回一个代表 HTML 标签的字符串。如果`text`值存在,该标签就包含可选值`text`;如果`text`不存在,该标签就不包含文本。对于段落元素,根据`text`是`"some text"`还是`nil`,闭包会返回"`<p>some text</p>`"或者"`<p />`"。
|
||||
|
||||
可以像实例方法那样去命名、使用`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)</\(heading.name)>"
|
||||
}
|
||||
print(heading.asHTML())
|
||||
// prints "<h1>some default text</h1>"
|
||||
```
|
||||
|
||||
例如,可以将一个闭包赋值给`asHTML`属性,这个闭包能在文本属性是 nil 时用默认文本,这是为了避免返回一个空的 `HTML` 标签:
|
||||
|
||||
```swift
|
||||
let heading = HTMLElement(name: "h1")
|
||||
let defaultText = "some default text"
|
||||
heading.asHTML = {
|
||||
return "<\(heading.name)>\(heading.text ?? defaultText)</\(heading.name)>"
|
||||
}
|
||||
print(heading.asHTML())
|
||||
// prints "<h1>some default text</h1>"
|
||||
```
|
||||
|
||||
> 注意:
|
||||
`asHTML`声明为`lazy`属性,因为只有当元素确实需要处理为HTML输出的字符串时,才需要使用`asHTML`。也就是说,在默认的闭包中可以使用`self`,因为只有当初始化完成以及`self`确实存在后,才能访问`lazy`属性。
|
||||
@ -501,7 +502,7 @@ paragraph = nil
|
||||
|
||||
>注意:
|
||||
Swift 有如下要求:只要在闭包内使用`self`的成员,就要用`self.someProperty`或者`self.someMethod()`(而不只是`someProperty`或`someMethod()`)。这提醒你可能会一不小心就捕获了`self`。
|
||||
|
||||
|
||||
<a name="defining_a_capture_list"></a>
|
||||
###定义捕获列表
|
||||
|
||||
@ -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)章节,获取更多关于捕获列表的信息
|
||||
|
||||
@ -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提供了在运行对可恢复错误抛出,捕获,传送和操作的高级支持。
|
||||
|
||||
@ -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
|
||||
|
||||
本页包含内容:
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
> 翻译+校对:[mmoaay](https://github.com/mmoaay)
|
||||
|
||||
> 2.1
|
||||
> 翻译:[Prayer](https://github.com/futantan)
|
||||
> 校对:[shanks](http://codebuild.me),2015-11-01
|
||||
|
||||
本页内容包括:
|
||||
|
||||
@ -8,6 +8,9 @@
|
||||
> 2.0
|
||||
> 翻译+校对:[buginux](https://github.com/buginux)
|
||||
|
||||
> 2.1
|
||||
> 翻译:[mmoaay](https://github.com/mmoaay)
|
||||
|
||||
|
||||
本页包含内容:
|
||||
|
||||
|
||||
@ -8,6 +8,9 @@
|
||||
> 2.0
|
||||
> 翻译+校对:[EudeMorgen](https://github.com/EudeMorgen)
|
||||
|
||||
> 2.1
|
||||
> 翻译:[mmoaay](https://github.com/mmoaay)
|
||||
|
||||
本页包含内容:
|
||||
|
||||
- [类型注解(Type Annotation)](#type_annotation)
|
||||
|
||||
@ -8,6 +8,9 @@
|
||||
> 2.0
|
||||
> 翻译+校对:[EudeMorgen](https://github.com/EudeMorgen)
|
||||
|
||||
> 2.1
|
||||
> 翻译:[mmoaay](https://github.com/mmoaay)
|
||||
|
||||
本页包含内容:
|
||||
|
||||
- [前缀表达式(Prefix Expressions)](#prefix_expressions)
|
||||
|
||||
@ -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没有
|
||||
```
|
||||
|
||||
<!--TODO:缺少in-out参数段落-->
|
||||
|
||||
<!--TODO:缺少in-out参数段落-->
|
||||
|
||||
<a name="special_kinds_of_parameters"></a>
|
||||
###特殊类型的参数
|
||||
@ -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)一节。
|
||||
|
||||
|
||||
<a name="enumerations_with_indirection"></a>
|
||||
### 间接的枚举
|
||||
### 间接的枚举
|
||||
|
||||
枚举有一个递归结构,就是说,枚举有着枚举类型自身实例的关联值的用例。然而,枚举类型的实例有值语义,意味着它们在内存中有着固定的位置。为了支持递归,编译器必需插入一个间接层。
|
||||
|
||||
|
||||
@ -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, *)
|
||||
|
||||
@ -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)
|
||||
|
||||
本页内容包括:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user