移除行末空格 (#782)

This commit is contained in:
BqLin
2018-05-06 19:13:01 +08:00
committed by 安正超
parent a3f0cae500
commit 08a76e561f
29 changed files with 1030 additions and 1030 deletions

View File

@ -13,7 +13,7 @@
> 校对:[shanks](http://codebuild.me)[overtrue](https://github.com/overtrue)
> 2.2
> 校对:[SketchK](https://github.com/SketchK)
> 校对:[SketchK](https://github.com/SketchK)
> 3.0
> 校对:[CMB](https://github.com/chenmingbiao)版本时间2016-09-13
@ -676,7 +676,7 @@ if let firstNumber = Int("4"), let secondNumber = Int("42"), firstNumber < secon
print("\(firstNumber) < \(secondNumber) < 100")
}
// 输出 "4 < 42 < 100"
if let firstNumber = Int("4") {
if let secondNumber = Int("42") {
if firstNumber < secondNumber && secondNumber < 100 {
@ -774,7 +774,7 @@ do {
func makeASandwich() throws {
// ...
}
do {
try makeASandwich()
eatASandwich()

View File

@ -390,7 +390,7 @@ for name in names[2...] {
}
// Brian
// Jack
for name in names[...2] {
print(name)
}

View File

@ -10,7 +10,7 @@
> 2.1
> 翻译:[DianQK](https://github.com/DianQK)
> 校对:[shanks](http://codebuild.me), [Realank](https://github.com/Realank),
> 校对:[shanks](http://codebuild.me), [Realank](https://github.com/Realank),
> 2.2
> 校对:[SketchK](https://github.com/SketchK)
@ -18,9 +18,9 @@
> 3.0
> 校对:[CMB](https://github.com/chenmingbiao)版本日期2016-09-13
> 3.0.1, shanks, 2016-11-11
> 4.0
> 翻译:[kemchenj](https://kemchenj.github.io/) 2017-09-21
> 翻译:[kemchenj](https://kemchenj.github.io/) 2017-09-21
> 4.1
> 翻译+校对:[mylittleswift](https://github.com/mylittleswift)
@ -43,7 +43,7 @@
- [字符串的 Unicode 表示形式](#unicode_representations_of_strings)
*字符串*是是一系列字符的集合,例如 `"hello, world"``"albatross"`。Swift 的字符串通过 `String` 类型来表示。
一个 `String` 的内容可以用许多方式读取,包括作为一个 `Character` 值的集合。
一个 `String` 的内容可以用许多方式读取,包括作为一个 `Character` 值的集合。
Swift 的 `String``Character` 类型提供了快速和兼容 Unicode 的方式供你的代码使用。创建和操作字符串的语法与 C 语言中字符串操作相似,轻量并且易读。字符串连接操作只需要简单地通过 `+` 符号将两个字符串相连即可。与 Swift 中其他值一样,能否更改字符串的值,取决于其被定义为常量还是变量。你也可以在字符串内插过程中使用字符串插入常量、变量、字面量表达成更长的字符串,这样可以很容易的创建自定义的字符串值,进行展示、存储以及打印。
@ -78,7 +78,7 @@ let someString = "Some string literal value"
let quotation = """
The White Rabbit put on his spectacles. "Where shall I begin,
please your Majesty?" he asked.
"Begin at the beginning," the King said gravely, "and go on
till you come to the end; then stop."
"""
@ -99,7 +99,7 @@ These are the same.
let softWrappedQuotation = """
The White Rabbit put on his spectacles. "Where shall I begin, \
please your Majesty?" he asked.
"Begin at the beginning," the King said gravely, "and go on \
till you come to the end; then stop."
"""
@ -109,10 +109,10 @@ till you come to the end; then stop."
```swift
let lineBreaks = """
This string starts with a line break.
It also ends with a line break.
"""
```
@ -283,11 +283,11 @@ print(badStart + end)
// 打印两行:
// one
// twothree
let goodStart = """
one
two
"""
print(goodStart + end)
// 打印三行:
@ -464,7 +464,7 @@ for index in greeting.indices {
> 注意
>
> 您可以使用 `startIndex` 和 `endIndex` 属性或者 `index(before:)` 、`index(after:)` 和 `index(_:offsetBy:)` 方法在任意一个确认的并遵循 `Collection` 协议的类型里面,如上文所示是使用在 `String` 中,您也可以使用在 `Array`、`Dictionary` 和 `Set` 中。
> 您可以使用 `startIndex` 和 `endIndex` 属性或者 `index(before:)` 、`index(after:)` 和 `index(_:offsetBy:)` 方法在任意一个确认的并遵循 `Collection` 协议的类型里面,如上文所示是使用在 `String` 中,您也可以使用在 `Array`、`Dictionary` 和 `Set` 中。
<a name="inserting_and_removing"></a>
### 插入和删除
@ -475,7 +475,7 @@ for index in greeting.indices {
var welcome = "hello"
welcome.insert("!", at: welcome.endIndex)
// welcome 变量现在等于 "hello!"
welcome.insert(contentsOf:" there", at: welcome.index(before: welcome.endIndex))
// welcome 变量现在等于 "hello there!"
```
@ -485,7 +485,7 @@ welcome.insert(contentsOf:" there", at: welcome.index(before: welcome.endIndex))
```swift
welcome.remove(at: welcome.index(before: welcome.endIndex))
// welcome 现在等于 "hello there"
let range = welcome.index(welcome.endIndex, offsetBy: -6)..<welcome.endIndex
welcome.removeSubrange(range)
// welcome 现在等于 "hello"
@ -493,7 +493,7 @@ welcome.removeSubrange(range)
> 注意
>
> 您可以使用 `insert(_:at:)`、`insert(contentsOf:at:)`、`remove(at:)` 和 `removeSubrange(_:)` 方法在任意一个确认的并遵循 `RangeReplaceableCollection` 协议的类型里面,如上文所示是使用在 `String` 中,您也可以使用在 `Array`、`Dictionary` 和 `Set` 中。
> 您可以使用 `insert(_:at:)`、`insert(contentsOf:at:)`、`remove(at:)` 和 `removeSubrange(_:)` 方法在任意一个确认的并遵循 `RangeReplaceableCollection` 协议的类型里面,如上文所示是使用在 `String` 中,您也可以使用在 `Array`、`Dictionary` 和 `Set` 中。
<a name="substrings"></a>
## 子字符串
@ -505,7 +505,7 @@ let greeting = "Hello, world!"
let index = greeting.index(of: ",") ?? greeting.endIndex
let beginning = greeting[..<index]
// beginning 的值为 "Hello"
// 把结果转化为 String 以便长期存储。
let newString = String(beginning)
```

View File

@ -14,7 +14,7 @@
> 2.2
> 校对:[SketchK](https://github.com/SketchK) 2016-05-13
> 3.0.1shanks2016-11-13
> 4.0
> 校对:[kemchenj](https://kemchenj.github.io/) 2017-09-21

View File

@ -9,7 +9,7 @@
> 翻译+校对:[chenmingbiao](https://github.com/chenmingbiao)
> 2.1
> 翻译:[Channe](https://github.com/Channe)[Realank](https://github.com/Realank)
> 翻译:[Channe](https://github.com/Channe)[Realank](https://github.com/Realank)
> 校对:[shanks](http://codebuild.me)2016-1-23
> 2.2
@ -377,7 +377,7 @@ Swift 为类类型提供了两种构造器来确保实例中所有存储型属
*指定构造器*是类中最主要的构造器。一个指定构造器将初始化类中提供的所有属性,并根据父类链往上调用父类合适的构造器来实现父类的初始化。
类倾向于拥有少量指定构造器,普遍的是一个类拥有一个指定构造器。指定构造器在初始化的地方通过“管道”将初始化过程持续到父类链。
类倾向于拥有少量指定构造器,普遍的是一个类拥有一个指定构造器。指定构造器在初始化的地方通过“管道”将初始化过程持续到父类链。
每一个类都必须至少拥有一个指定构造器。在某些情况下,许多类通过继承了父类中的指定构造器而满足了这个条件。具体内容请参考后续章节[构造器的自动继承](#automatic_initializer_inheritance)。
@ -746,15 +746,15 @@ for item in breakfastList {
```swift
let wholeNumber: Double = 12345.0
let pi = 3.14159
if let valueMaintained = Int(exactly: wholeNumber) {
print("\(wholeNumber) conversion to Int maintains value of \(valueMaintained)")
}
// 打印 "12345.0 conversion to Int maintains value of 12345"
let valueChanged = Int(exactly: pi)
// valueChanged 是 Int? 类型,不是 Int 类型
if valueChanged == nil {
print("\(pi) conversion to Int does not maintain value")
}
@ -767,7 +767,7 @@ if valueChanged == nil {
struct Animal {
let species: String
init?(species: String) {
if species.isEmpty {
if species.isEmpty {
return nil
}
self.species = species
@ -994,7 +994,7 @@ class UntitledDocument: Document {
在这个例子中,如果在调用父类的可失败构造器 `init?(name:)` 时传入的是空字符串,那么强制解包操作会引发运行时错误。不过,因为这里是通过非空的字符串常量来调用它,所以并不会发生运行时错误。
<a name="the_init!_failable_initializer"></a>
### init!可失败构造器
### init!可失败构造器
通常来说我们通过在 `init` 关键字后添加问号的方式(`init?`)来定义一个可失败构造器,但你也可以通过在 `init` 后面添加惊叹号的方式来定义一个可失败构造器(`init!`),该可失败构造器将会构建一个对应类型的隐式解包可选类型的对象。

View File

@ -13,7 +13,7 @@
> 校对:[shanks](http://codebuild.me)
>
> 2.2
> 翻译+校对:[SketchK](https://github.com/SketchK)
> 翻译+校对:[SketchK](https://github.com/SketchK)
>
> 3.0
> 校对:[CMB](https://github.com/chenmingbiao)版本日期2016-09-13
@ -699,7 +699,7 @@ class City: Location, Named {
func beginConcert(in location: Location & Named) {
print("Hello, \(location.name)!")
}
let seattle = City(name: "Seattle", latitude: 47.6, longitude: -122.3)
beginConcert(in: seattle)
// Prints "Hello, Seattle!"

View File

@ -76,7 +76,7 @@ func swapTwoStrings(_ a: inout String, _ b: inout String) {
a = b
b = temporaryA
}
func swapTwoDoubles(_ a: inout Double, _ b: inout Double) {
let temporaryA = a
a = b

View File

@ -210,7 +210,7 @@ Swift 提供了两种办法用来解决你在使用类的属性时所遇到的
> 注意
>
> 当 ARC 设置弱引用为 `nil` 时,属性观察不会被触发。
> 当 ARC 设置弱引用为 `nil` 时,属性观察不会被触发。
下面的例子跟上面 `Person``Apartment` 的例子一致,但是有一个重要的区别。这一次,`Apartment``tenant` 属性被声明为弱引用:
@ -271,10 +271,10 @@ unit4A = nil
上面的两段代码展示了变量 `john``unit4A` 在被赋值为 `nil` 后,`Person` 实例和 `Apartment` 实例的析构函数都打印出“销毁”的信息。这证明了引用循环被打破了。
> 注意
>
> 在使用垃圾收集的系统里,弱指针有时用来实现简单的缓冲机制,因为没有强引用的对象只会在内存压力触发垃圾收集时才被销毁。但是在 ARC 中,一旦值的最后一个强引用被移除,就会被立即销毁,这导致弱引用并不适合上面的用途。
> 注意
>
> 在使用垃圾收集的系统里,弱指针有时用来实现简单的缓冲机制,因为没有强引用的对象只会在内存压力触发垃圾收集时才被销毁。但是在 ARC 中,一旦值的最后一个强引用被移除,就会被立即销毁,这导致弱引用并不适合上面的用途。
<a name="unowned_references"></a>
### 无主引用

View File

@ -28,7 +28,7 @@ Swift 也保证同时访问同一块内存时不会冲突,通过约束代码
```swift
// 向 one 所在的内存区域发起一次写操作
var one = 1
// 向 one 所在的内存区域发起一次读操作
print("We're number \(one)!")
```
@ -42,7 +42,7 @@ print("We're number \(one)!")
而当你添加预算项进入表里的时候,它只是一个临时的,错误的状态,因为总数还没有呗更新。在添加预算项的过程中读取总数就会读取到错误的信息。
这个例子也演示了你在修复内存访问冲突时会遇到的问题:有时修复的方式会有很多种,但哪一种是正确的就不总是那么明显了。在这个例子里,根据你是否需要更新后的总数,$5 和 $320 都可能是正确的值。在你修复访问冲突之前,你需要决定它的倾向。
> 注意
>
> 如果你写过并发和多线程的代码,内存访问冲突也许是同样的问题。然而,这里访问冲突的讨论是在单线程的情境下讨论的,并没有使用并发或者多线程。
@ -65,7 +65,7 @@ print("We're number \(one)!")
func oneMore(than number: Int) -> Int {
return number + 1
}
var myNumber = 1
myNumber = oneMore(than: myNumber)
print(myNumber)
@ -85,11 +85,11 @@ print(myNumber)
```swift
var stepSize = 1
func increment(_ number: inout Int) {
number += stepSize
}
increment(&stepSize)
// 错误stepSize 访问冲突
```
@ -104,7 +104,7 @@ increment(&stepSize)
// 复制一份副本
var copyOfStepSize = stepSize
increment(&copyOfStepSize)
// 更新原来的值
stepSize = copyOfStepSize
// stepSize 现在的值是 2
@ -159,7 +159,7 @@ extension Player {
balance(&teammate.health, &health)
}
}
var oscar = Player(name: "Oscar", health: 10, energy: 10)
var maria = Player(name: "Maria", health: 5, energy: 10)
oscar.shareHealth(with: &maria) // 正常

View File

@ -12,7 +12,7 @@
> 翻译:[Prayer](https://github.com/futantan)
> 校对:[shanks](http://codebuild.me)2015-11-01
> 2.2
> 2.2
> 翻译+校对:[SketchK](https://github.com/SketchK) 2016-05-17
> 3.0.1
@ -77,7 +77,7 @@ Open 只能作用于类和类的成员,它和 Public 的区别如下:
* Public 或者其它更严访问级别的类成员,只能在其定义的模块内部的子类中重写。
* Open 的类,可以在其定义的模块中被继承,也可以在引用它的模块中被继承。
* Open 的类成员,可以在其定义的模块中子类中重写,也可以在引用它的模块中的子类重写。
把一个类标记为 `open`,明确的表示你已经充分考虑过外部模块使用此类作为父类的影响,并且设计好了你的类的代码了。
<a name="guiding_principle_of_access_levels"></a>
@ -126,7 +126,7 @@ public class SomePublicClass {}
internal class SomeInternalClass {}
fileprivate class SomeFilePrivateClass {}
private class SomePrivateClass {}
public var somePublicVariable = 0
internal let someInternalConstant = 0
fileprivate func someFilePrivateFunction() {}
@ -158,18 +158,18 @@ public class SomePublicClass { // 显式 public 类
fileprivate func someFilePrivateMethod() {} // 显式 fileprivate 类成员
private func somePrivateMethod() {} // 显式 private 类成员
}
class SomeInternalClass { // 隐式 internal 类
var someInternalProperty = 0 // 隐式 internal 类成员
fileprivate func someFilePrivateMethod() {} // 显式 fileprivate 类成员
private func somePrivateMethod() {} // 显式 private 类成员
}
fileprivate class SomeFilePrivateClass { // 显式 fileprivate 类
func someFilePrivateMethod() {} // 隐式 fileprivate 类成员
private func somePrivateMethod() {} // 显式 private 类成员
}
private class SomePrivateClass { // 显式 private 类
func somePrivateMethod() {} // 隐式 private 类成员
}

View File

@ -11,7 +11,7 @@
> 2.1
> 校对:[shanks](http://codebuild.me)2015-11-01
>
> 2.2
> 2.2
> 翻译+校对:[SketchK](https://github.com/SketchK) 2016-05-17
>
> 3.0
@ -329,7 +329,7 @@ signedOverflow = signedOverflow &- 1
struct Vector2D {
var x = 0.0, y = 0.0
}
extension Vector2D {
static func + (left: Vector2D, right: Vector2D) -> Vector2D {
return Vector2D(x: left.x + right.x, y: left.y + right.y)
@ -449,7 +449,7 @@ Swift 为以下自定义类型提等价运算符供合成实现:
struct Vector3D: Equatable {
var x = 0.0, y = 0.0, z = 0.0
}
let twoThreeFour = Vector3D(x: 2.0, y: 3.0, z: 4.0)
let anotherTwoThreeFour = Vector3D(x: 2.0, y: 3.0, z: 4.0)
if twoThreeFour == anotherTwoThreeFour {