修正标点、更新 04_revision_history.md (#775)

* 修正全角逗号、句号的使用

* 修正逗号使用

* 修正一处代码空格错误

* 修正斜体范围,引用的空格使用

* 修正示例代码错误

* 修正标点,修正示例代码

* 修正标点

* 修正标点

* 添加 Swift 3.1 的更新

* 修改 Swift 3.0.1 位置

* 添加 Swift 4.0.3 更新

* 添加 Swift 4.1 更新

* 修正示例代码
This commit is contained in:
BqLin
2018-03-01 11:26:22 +08:00
committed by 安正超
parent 73ea47e3eb
commit 53ac4e8a87
4 changed files with 118 additions and 42 deletions

View File

@ -31,10 +31,22 @@
>
> 3.0.1
> 翻译+校对:[shanks](http://codebuild.me)2016-11-10
>
> 3.1
> 翻译+校对:[bq](https://github.com/bqlin)2018-02-22
>
> 4.0
> 翻译+校对:[bq](https://github.com/bqlin)2018-02-22
>
> 4.1
> 翻译+校对:[bq](https://github.com/bqlin)2018-02-22
本页面根据 [Document Revision History](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/RevisionHistory.html) 进行适配更新。
本页内容包括:
- [Swift 4.0 更新](#swift_4_1)
- [Swift 4.0 更新](#swift_4_0)
- [Swift 3.1 更新](#swift_3_1)
- [Swift 3.0 更新](#swift_3_0)
- [Swift 2.2 更新](#swift_2_2)
@ -44,9 +56,87 @@
- [Swift 1.1 更新](#swift_1_1)
- [Swift 1.0 更新](#swift_1_0)
<a name="swift_4_1"></a>
### Swift 4.1 更新
<table class="graybox" border="0" cellspacing="0" cellpadding="5">
<thead>
<tr>
<th scope="col" width="100">发布日期</th>
<th scope="col">语法变更记录</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row">2018-02-06</td>
<td>
<ul class="list-bullet">
<li>更新至 Swift 4.1。</li>
<li>添加了<a href='https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html#//apple_ref/doc/uid/TP40014097-CH25-ID574'>有条件遵守协议</a>章节,其中包含有关调节协议一致性的内容。</li>
<li><a href='https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Generics.html#//apple_ref/doc/uid/TP40014097-CH26-ID575'>在其关联类型约束中使用协议</a>章节添加了递归协议约束的内容。</li>
<li><a href='https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/doc/uid/TP40014097-CH33-ID539'>条件编译块</a>章节中添加有关 <code>canImport()</code><code>targetEnvironment()</code> 平台条件的内容。</li>
</ul>
</td>
</tr>
</tbody>
</table>
<a name="swift_4_0"></a>
### Swift 4.0 更新
<table class="graybox" border="0" cellspacing="0" cellpadding="5">
<thead>
<tr>
<th scope="col" width="100">发布日期</th>
<th scope="col">语法变更记录</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row">2017-12-04</td>
<td>
<ul class="list-bullet">
<li>更新至 Swift 4.0.3。</li>
<li>更新 <a href='https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Expressions.html#//apple_ref/doc/uid/TP40014097-CH32-ID563'>Key-Path 表达式</a>,现在 key path 支持下标子路径。</li>
</ul>
</td>
</tr>
</tbody>
</table>
<a name="swift_3_1"></a>
### Swift 3.1 更新
<table class="graybox" border="0" cellspacing="0" cellpadding="5">
<thead>
<tr>
<th scope="col" width="100">发布日期</th>
<th scope="col">语法变更记录</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row">2017-03-27</td>
<td>
<ul class="list-bullet">
<li>更新至 Swift 3.1。</li>
<li>增加<a href='https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Generics.html#//apple_ref/doc/uid/TP40014097-CH26-ID553'>通用 Where 子句扩展</a>,其中包含需要的扩展信息。</li>
<li>增加了一个区间迭代的例子到<a href='https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/ControlFlow.html#//apple_ref/doc/uid/TP40014097-CH9-ID121'>For-In 循环</a>章节。</li>
<li>增加一个可失败数值转换的例子到<a href='https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.html#//apple_ref/doc/uid/TP40014097-CH18-ID224'>可失败构造器</a>章节。</li>
<li>增加关于使用 Swift 语言版本的 <code>available</code> 特性信息到<a href='https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Attributes.html#//apple_ref/doc/uid/TP40014097-CH35-ID348'>声明特性</a>章节。</li>
<li>更新了<a href='https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/doc/uid/TP40014097-CH31-ID449'>函数类型</a>章节中的描述,注意在写函数类型时不允许使用参数标签。</li>
<li>更新了<a href='https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/doc/uid/TP40014097-CH33-ID539'>条件编译块</a>章节中的 Swift 语言版本号的描述,现在可以使用可选的补丁版本号。</li>
<li>更新了<a href='https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/doc/uid/TP40014097-CH31-ID449'>函数类型</a>章节的描述,现在 Swift 区分了采用多参数的函数和采用元组类型的单个参数的函数。</li>
<li><a href='https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Expressions.html#//apple_ref/doc/uid/TP40014097-CH32-ID383'>表达式</a>章节中删除了动态表达式的部分,现在 <code>type(of:)</code> 是 Swift 标准库函数。</li>
</ul>
</td>
</tr>
</tbody>
</table>
<a name="swift_3_0"></a>
### Swift 3.0 更新
<table class="graybox" border="0" cellspacing="0" cellpadding="5">
<thead>
<tr>
@ -77,20 +167,6 @@
</ul>
</td>
</tr>
</tbody>
</table>
<a name="swift_3_0"></a>
### Swift 3.0 更新
<table class="graybox" border="0" cellspacing="0" cellpadding="5">
<thead>
<tr>
<th scope="col" width="100">发布日期</th>
<th scope="col">语法变更记录</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row">2016-09-13</td>
<td><ul class="list-bullet">

View File

@ -24,7 +24,7 @@
- [下标用法](#subscript_usage)
- [下标选项](#subscript_options)
*下标*可以定义在类、结构体和枚举中,是访问集合列表或序列中元素的快捷方式。可以使用下标的索引,设置和获取值,而不需要再调用对应的存取方法。举例来说,用下标访问一个`Array`实例中的元素可以写作`someArray[index]`,访问`Dictionary`实例中的元素可以写作`someDictionary[key]`
*下标*可以定义在类、结构体和枚举中,是访问集合列表或序列中元素的快捷方式。可以使用下标的索引,设置和获取值,而不需要再调用对应的存取方法。举例来说,用下标访问一个`Array`实例中的元素可以写作`someArray[index]`,访问`Dictionary`实例中的元素可以写作`someDictionary[key]`
一个类型可以定义多个下标,通过不同索引类型进行重载。下标不限于一维,你可以定义具有多个入参的下标满足自定义类型的需求。
@ -111,7 +111,7 @@ struct Matrix {
init(rows: Int, columns: Int) {
self.rows = rows
self.columns = columns
grid = Array(count: rows * columns, repeatedValue: 0.0)
grid = Array(repeating: 0.0, count: rows * columns)
}
func indexIsValid(row: Int, column: Int) -> Bool {
return row >= 0 && row < rows && column >= 0 && column < columns

View File

@ -24,7 +24,7 @@
一个类可以*继承*另一个类的方法,属性和其它特性。当一个类继承其它类时,继承类叫*子类*,被继承类叫*超类(或父类)*。在 Swift 中,继承是区分「类」与其它类型的一个基本特征。
在 Swift 中,类可以调用和访问超类的方法属性和下标并且可以重写这些方法属性和下标来优化或修改它们的行为。Swift 会检查你的重写定义在超类中是否有匹配的定义,以此确保你的重写行为是正确的。
在 Swift 中,类可以调用和访问超类的方法属性和下标并且可以重写这些方法属性和下标来优化或修改它们的行为。Swift 会检查你的重写定义在超类中是否有匹配的定义,以此确保你的重写行为是正确的。
可以为类中继承来的属性添加属性观察器,这样一来,当属性值改变时,类就会被通知到。可以为任何属性添加属性观察器,无论它原本被定义为存储型属性还是计算型属性。
@ -240,6 +240,6 @@ print("AutomaticCar: \(automatic.description)")
你可以通过把方法,属性或下标标记为*`final`*来防止它们被重写,只需要在声明关键字前加上`final`修饰符即可(例如:`final var``final func``final class func`,以及`final subscript`)。
如果你重写了带有`final`标记的方法属性或下标,在编译时会报错。在类扩展中的方法,属性或下标也可以在扩展的定义里标记为 final 的。
如果你重写了带有`final`标记的方法属性或下标,在编译时会报错。在类扩展中的方法,属性或下标也可以在扩展的定义里标记为 final 的。
你可以通过在关键字`class`前添加`final`修饰符(`final class`)来将整个类标记为 final 的。这样的类是不可被继承的,试图继承这样的类会导致编译报错。

View File

@ -369,7 +369,7 @@ Swift 为类类型提供了两种构造器来确保实例中所有存储型属
*指定构造器*是类中最主要的构造器。一个指定构造器将初始化类中提供的所有属性,并根据父类链往上调用父类合适的构造器来实现父类的初始化。
类倾向于拥有少量指定构造器,普遍的是一个类拥有一个指定构造器。指定构造器在初始化的地方通过 "管道" 将初始化过程持续到父类链。
类倾向于拥有少量指定构造器,普遍的是一个类拥有一个指定构造器。指定构造器在初始化的地方通过“管道”将初始化过程持续到父类链。
每一个类都必须至少拥有一个指定构造器。在某些情况下,许多类通过继承了父类中的指定构造器而满足了这个条件。具体内容请参考后续章节[构造器的自动继承](#automatic_initializer_inheritance)。
@ -751,7 +751,8 @@ struct Animal {
let species: String
init?(species: String) {
if species.isEmpty {
return nil }
return nil
}
self.species = species
}
}
@ -1051,8 +1052,7 @@ struct Chessboard {
}
return temporaryBoard
}()
func squareIsBlackAtRow(row: Int, column: Int) -> Bool {
func squareIsBlackAt(row: Int, column: Int) -> Bool {
return boardColors[(row * 8) + column]
}
}
@ -1062,8 +1062,8 @@ struct Chessboard {
```swift
let board = Chessboard()
print(board.squareIsBlackAtRow(0, column: 1))
// 打印 "true"
print(board.squareIsBlackAtRow(7, column: 7))
// 打印 "false"
print(board.squareIsBlackAt(row: 0, column: 1))
// Prints "true"
print(board.squareIsBlackAt(row: 7, column: 7))
// Prints "false
```