移除行末空格 (#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

@ -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) // 正常