diff --git a/source/chapter2/11_Methods.md b/source/chapter2/11_Methods.md
index c39669e6..6bb16678 100755
--- a/source/chapter2/11_Methods.md
+++ b/source/chapter2/11_Methods.md
@@ -72,18 +72,18 @@ func increment() {
```swift
struct Point {
var x = 0.0, y = 0.0
- func isToTheRightOfX(_ x: Double) -> Bool {
+ func isToTheRightOf(x: Double) -> Bool {
return self.x > x
}
}
let somePoint = Point(x: 4.0, y: 5.0)
-if somePoint.isToTheRightOfX(1.0) {
+if somePoint.isToTheRightOf(x: 1.0) {
print("This point is to the right of the line where x == 1.0")
}
// 打印“This point is to the right of the line where x == 1.0”
```
-如果不使用 `self` 前缀,Swift 就认为两次使用的 `x` 都指的是名称为 `x` 的函数参数。
+如果不使用 `self` 前缀,Swift会认为 `x` 的两个用法都引用了名为 `x` 的方法参数。
### 在实例方法中修改值类型
@@ -97,24 +97,24 @@ if somePoint.isToTheRightOfX(1.0) {
```swift
struct Point {
var x = 0.0, y = 0.0
- mutating func moveByX(_ deltaX: Double, y deltaY: Double) {
+ mutating func moveBy(x deltaX: Double, y deltaY: Double) {
x += deltaX
y += deltaY
}
}
var somePoint = Point(x: 1.0, y: 1.0)
-somePoint.moveByX(2.0, y: 3.0)
+somePoint.moveBy(x: 2.0, y: 3.0)
print("The point is now at (\(somePoint.x), \(somePoint.y))")
// 打印“The point is now at (3.0, 4.0)”
```
-上面的 `Point` 结构体定义了一个可变方法 `moveByX(_:y:)` 来移动 `Point` 实例到给定的位置。该方法被调用时修改了这个点,而不是返回一个新的点。方法定义时加上了 `mutating` 关键字,从而允许修改属性。
+上面的 `Point` 结构体定义了一个可变方法 `moveBy(x:y :)` 来移动 `Point` 实例到给定的位置。该方法被调用时修改了这个点,而不是返回一个新的点。方法定义时加上了 `mutating` 关键字,从而允许修改属性。
注意,不能在结构体类型的常量(a constant of structure type)上调用可变方法,因为其属性不能被改变,即使属性是变量属性,详情参见[常量结构体的存储属性](./10_Properties.html#stored_properties_of_constant_structure_instances):
```swift
let fixedPoint = Point(x: 3.0, y: 3.0)
-fixedPoint.moveByX(2.0, y: 3.0)
+fixedPoint.moveBy(x: 2.0, y: 3.0)
// 这里将会报告一个错误
```
@@ -138,26 +138,26 @@ struct Point {
```swift
enum TriStateSwitch {
- case Off, Low, High
+ case off, low, high
mutating func next() {
switch self {
- case .Off:
- self = .Low
- case .Low:
- self = .High
- case .High:
- self = .Off
+ case .off:
+ self = .low
+ case .low:
+ self = .high
+ case .high:
+ self = .off
}
}
}
-var ovenLight = TriStateSwitch.Low
+var ovenLight = TriStateSwitch.low
ovenLight.next()
-// ovenLight 现在等于 .High
+// ovenLight 现在等于 .high
ovenLight.next()
-// ovenLight 现在等于 .Off
+// ovenLight 现在等于 .off
```
-上面的例子中定义了一个三态开关的枚举。每次调用 `next()` 方法时,开关在不同的电源状态(`Off`,`Low`,`High`)之间循环切换。
+上面的例子中定义了一个三态切换的枚举。每次调用 `next()` 方法时,开关在不同的电源状态(`off`, `low`, `high`)之间循环切换。
## 类型方法
@@ -179,7 +179,7 @@ class SomeClass {
SomeClass.someTypeMethod()
```
-在类型方法的方法体(body)中,`self` 指向这个类型本身,而不是类型的某个实例。这意味着你可以用 `self` 来消除类型属性和类型方法参数之间的歧义(类似于我们在前面处理实例属性和实例方法参数时做的那样)。
+在类型方法的方法体(body)中,`self` 属性指向这个类型本身,而不是类型的某个实例。这意味着你可以用 `self` 来消除类型属性和类型方法参数之间的歧义(类似于我们在前面处理实例属性和实例方法参数时做的那样)。
一般来说,在类型方法的方法体中,任何未限定的方法和属性名称,可以被本类中其他的类型方法和类型属性引用。一个类型方法可以直接通过类型方法的名称调用本类中的其它类型方法,而无需在方法名称前面加上类型名称。类似地,在结构体和枚举中,也能够直接通过类型属性的名称访问本类中的类型属性,而不需要前面加上类型名称。
diff --git a/source/chapter2/25_Access_Control.md b/source/chapter2/25_Access_Control.md
index 8a315725..a8e9a409 100644
--- a/source/chapter2/25_Access_Control.md
+++ b/source/chapter2/25_Access_Control.md
@@ -155,7 +155,7 @@ private class SomePrivateClass { // 显式 private 类
```swift
func someFunction() -> (SomeInternalClass, SomePrivateClass) {
- // 此处是函数实现部分
+ // 此处是函数实现部分
}
```
@@ -165,7 +165,7 @@ func someFunction() -> (SomeInternalClass, SomePrivateClass) {
```swift
private func someFunction() -> (SomeInternalClass, SomePrivateClass) {
- // 此处是函数实现部分
+ // 此处是函数实现部分
}
```
@@ -180,10 +180,10 @@ private func someFunction() -> (SomeInternalClass, SomePrivateClass) {
```swift
public enum CompassPoint {
- case North
- case South
- case East
- case West
+ case north
+ case south
+ case east
+ case west
}
```
@@ -208,11 +208,11 @@ public enum CompassPoint {
```swift
public class A {
- private func someMethod() {}
+ private func someMethod() {}
}
internal class B: A {
- override internal func someMethod() {}
+ override internal func someMethod() {}
}
```