@@ -48,7 +48,7 @@ Swift 数组的类型完整写作 `Array<Element>`,其中 `Element` 是数组
48
48
``` swift
49
49
var someInts: [Int ] = []
50
50
print (" someInts is of type [Int] with \( someInts.count ) items." )
51
- // 打印 " someInts is of type [Int] with 0 items."
51
+ // 打印 “ someInts is of type [Int] with 0 items.“
52
52
```
53
53
54
54
<!--
@@ -67,7 +67,7 @@ print("someInts is of type [Int] with \(someInts.count) items.")
67
67
68
68
``` swift
69
69
someInts.append (3 )
70
- // someInts 现在包含 1 个类型为 Int 的值。
70
+ // someInts 现在包含 1 个类型为 Int 的值
71
71
someInts = []
72
72
// someInts 现在是一个空数组, 但它仍是 [Int] 类型的
73
73
```
@@ -154,7 +154,7 @@ var sixDoubles = threeDoubles + anotherThreeDoubles
154
154
155
155
``` swift
156
156
var shoppingList: [String ] = [" Eggs" , " Milk" ]
157
- // shoppingList has been initialized with two initial items
157
+ // shoppingList 已经用两个初始项进行了初始化
158
158
```
159
159
160
160
<!--
@@ -196,7 +196,7 @@ var shoppingList = ["Eggs", "Milk"]
196
196
197
197
``` swift
198
198
print (" The shopping list contains \( shoppingList.count ) items." )
199
- // 打印 " The shopping list contains 2 items."
199
+ // 打印 “ The shopping list contains 2 items.“
200
200
```
201
201
202
202
<!--
@@ -216,7 +216,7 @@ if shoppingList.isEmpty {
216
216
} else {
217
217
print (" The shopping list isn't empty." )
218
218
}
219
- // 打印 " The shopping list isn't empty."
219
+ // 打印 “ The shopping list isn't empty.“
220
220
```
221
221
222
222
<!--
@@ -236,7 +236,7 @@ if shoppingList.isEmpty {
236
236
237
237
``` swift
238
238
shoppingList.append (" Flour" )
239
- // shoppingList 现在包含 3 个项目 ,而有人正在做煎饼
239
+ // shoppingList 现在包含 3 项 ,而有人正在做煎饼
240
240
```
241
241
242
242
<!--
@@ -253,9 +253,9 @@ shoppingList.append("Flour")
253
253
254
254
``` swift
255
255
shoppingList += [" Baking Powder" ]
256
- // shoppingList 现在包含 4 个项目
256
+ // shoppingList 现在包含 4 项
257
257
shoppingList += [" Chocolate Spread" , " Cheese" , " Butter" ]
258
- // shoppingList 现在包含 7 个项目
258
+ // shoppingList 现在包含 7 项
259
259
```
260
260
261
261
<!--
@@ -275,7 +275,7 @@ shoppingList += ["Chocolate Spread", "Cheese", "Butter"]
275
275
276
276
``` swift
277
277
var firstItem = shoppingList[0 ]
278
- // firstItem 的值为 " Eggs"
278
+ // firstItem 的值为 “ Eggs”
279
279
```
280
280
281
281
<!--
@@ -294,7 +294,7 @@ var firstItem = shoppingList[0]
294
294
295
295
``` swift
296
296
shoppingList[0 ] = " Six eggs"
297
- // the first item in the list is now equal to " Six eggs" rather than " Eggs"
297
+ // 列表中的第一个项现在是 “ Six eggs” 而不是 “ Eggs”
298
298
```
299
299
300
300
<!--
@@ -315,11 +315,11 @@ shoppingList[0] = "Six eggs"
315
315
to make that index become valid.
316
316
-->
317
317
318
- 您还可以使用下标语法一次更改一个范围的值,即使替换值集的长度与要替换的范围不同。以下示例将` "Chocolate Spread" ` , ` "Cheese" ` 和 ` "Butter" ` 替换为 ` "Bananas" ` 和 ` "Apples" ` :
318
+ 您还可以使用下标语法一次更改一个范围的值,即使替换值集的长度与要替换的范围不同。以下示例将 ` "Chocolate Spread" ` , ` "Cheese" ` 和 ` "Butter" ` 替换为 ` "Bananas" ` 和 ` "Apples" ` :
319
319
320
320
``` swift
321
321
shoppingList[4 ... 6 ] = [" Bananas" , " Apples" ]
322
- // shoppingList now contains 6 items
322
+ // shoppingList 现在包含 6 项
323
323
```
324
324
325
325
<!--
@@ -336,8 +336,8 @@ shoppingList[4...6] = ["Bananas", "Apples"]
336
336
337
337
``` swift
338
338
shoppingList.insert (" Maple Syrup" , at : 0 )
339
- // shoppingList now contains 7 items
340
- // " Maple Syrup" is now the first item in the list
339
+ // shoppingList 现在包含 7 项
340
+ // ” Maple Syrup“ 现在是列表中的第一项
341
341
```
342
342
343
343
<!--
@@ -358,9 +358,9 @@ shoppingList.insert("Maple Syrup", at: 0)
358
358
359
359
``` swift
360
360
let mapleSyrup = shoppingList.remove (at : 0 )
361
- // the item that was at index 0 has just been removed
362
- // shoppingList now contains 6 items, and no Maple Syrup
363
- // the mapleSyrup constant is now equal to the removed " Maple Syrup" string
361
+ // 索引 0 处的项刚刚被移除了
362
+ // shoppingList 现在包含 6 项,且不包含 Maple Syrup
363
+ // mapleSyrup 常量现在等于已移除的 “ Maple Syrup” 字符串
364
364
```
365
365
366
366
<!--
@@ -382,7 +382,7 @@ let mapleSyrup = shoppingList.remove(at: 0)
382
382
383
383
``` swift
384
384
firstItem = shoppingList[0 ]
385
- // firstItem is now equal to " Six eggs"
385
+ // firstItem 现在等于 “ Six eggs”
386
386
```
387
387
388
388
<!--
@@ -399,9 +399,9 @@ firstItem = shoppingList[0]
399
399
400
400
``` swift
401
401
let apples = shoppingList.removeLast ()
402
- // the last item in the array has just been removed
403
- // shoppingList now contains 5 items, and no apples
404
- // the apples constant is now equal to the removed " Apples" string
402
+ // 数组中的最后一项刚刚被移除了
403
+ // shoppingList 现在包含 5 项,且不包含 apples
404
+ // apples 常量现在等于已移除的 “ Apples” 字符串
405
405
```
406
406
407
407
<!--
@@ -475,7 +475,7 @@ for (index, value) in shoppingList.enumerated() {
475
475
```
476
476
-->
477
477
478
- 有关 ` for- in ` 循环的更多信息,请参阅 < doc:ControlFlow#For-In-Loops > .
478
+ 有关 ` for ` - ` in ` 循环的更多信息,请参阅 < doc:ControlFlow#For-In-Loops > .
479
479
480
480
## 集合
481
481
@@ -508,7 +508,7 @@ Swift 集合的类型写作 `Set<Element>`,其中 `Element` 是集合允许存
508
508
``` swift
509
509
var letters = Set < Character > ()
510
510
print (" letters is of type Set<Character> with \( letters.count ) items." )
511
- // 打印 " letters is of type Set<Character> with 0 items."
511
+ // 打印 “ letters is of type Set<Character> with 0 items.“
512
512
```
513
513
514
514
<!--
@@ -527,9 +527,9 @@ print("letters is of type Set<Character> with \(letters.count) items.")
527
527
528
528
``` swift
529
529
letters.insert (" a" )
530
- // letters 现在包含 1 个类型为 Character 的值。
530
+ // letters 现在包含 1 个类型为 Character 的值
531
531
letters = []
532
- // letters 现在是一个空集合,但仍然是 Set<Character> 类型。
532
+ // letters 现在是一个空集合,但仍然是 Set<Character> 类型
533
533
```
534
534
535
535
<!--
@@ -552,7 +552,7 @@ letters = []
552
552
553
553
``` swift
554
554
var favoriteGenres: Set <String > = [" Rock" , " Classical" , " Hip hop" ]
555
- // favoriteGenres 已经用三个初始元素进行了初始化。
555
+ // favoriteGenres 已经用三个初始元素进行了初始化
556
556
```
557
557
558
558
<!--
@@ -592,7 +592,7 @@ var favoriteGenres: Set = ["Rock", "Classical", "Hip hop"]
592
592
593
593
``` swift
594
594
print (" I have \( favoriteGenres.count ) favorite music genres." )
595
- // 打印 " I have 3 favorite music genres."
595
+ // 打印 “ I have 3 favorite music genres.“
596
596
```
597
597
598
598
<!--
@@ -613,7 +613,7 @@ if favoriteGenres.isEmpty {
613
613
} else {
614
614
print (" I have particular music preferences." )
615
615
}
616
- // 打印 " I have particular music preferences."
616
+ // 打印 “ I have particular music preferences.“
617
617
```
618
618
619
619
<!--
@@ -633,7 +633,7 @@ if favoriteGenres.isEmpty {
633
633
634
634
``` swift
635
635
favoriteGenres.insert (" Jazz" )
636
- // favoriteGenres 现在包含 4 个元素
636
+ // favoriteGenres 现在包含 4 项
637
637
```
638
638
639
639
<!--
@@ -654,7 +654,7 @@ if let removedGenre = favoriteGenres.remove("Rock") {
654
654
} else {
655
655
print (" I never much cared for that." )
656
656
}
657
- // 打印 " Rock? I'm over it."
657
+ // 打印 “ Rock? I'm over it.“
658
658
```
659
659
660
660
<!--
@@ -678,7 +678,7 @@ if favoriteGenres.contains("Funk") {
678
678
} else {
679
679
print (" It's too funky in here." )
680
680
}
681
- // 打印 " It's too funky in here."
681
+ // 打印 “ It's too funky in here.“
682
682
```
683
683
684
684
<!--
@@ -808,7 +808,7 @@ oddDigits.symmetricDifference(singleDigitPrimeNumbers).sorted()
808
808
Tracking bug is <rdar://problem/35301593>
809
809
-->
810
810
811
- ### 集合成员资格与相等性
811
+ ### 集合成员关系与相等
812
812
813
813
下图描述了三个集合 --- ` a ` 、` b ` 和 ` c ` ,其中重叠区域表示集合间共享的元素。集合 ` a ` 是集合 ` b ` 的 ** 超集** ,因为 ` a ` 包含了 ` b ` 中的所有元素。相反,集合 ` b ` 是集合 ` a ` 的 ** 子集** ,因为 ` b ` 中的所有元素都包含在 ` a ` 中。集合 ` b ` 和集合 ` c ` 是 ** 不相交的** ,因为它们没有任何共同的元素。
814
814
@@ -884,7 +884,7 @@ Swift 字典的完整类型写作 `Dictionary<Key, Value>`,其中 `Key` 是可
884
884
885
885
``` swift
886
886
var namesOfIntegers: [Int : String ] = [: ]
887
- // namesOfIntegers 是一个空的 [Int: String] 字典。
887
+ // namesOfIntegers 是一个空的 [Int: String] 字典
888
888
```
889
889
890
890
<!--
@@ -902,9 +902,9 @@ var namesOfIntegers: [Int: String] = [:]
902
902
903
903
``` swift
904
904
namesOfIntegers[16 ] = " sixteen"
905
- // namesOfIntegers 现在包含 1 个键值对。
905
+ // namesOfIntegers 现在包含 1 个键值对
906
906
namesOfIntegers = [: ]
907
- // namesOfIntegers 再次成为一个类型为 [Int: String] 的空字典。
907
+ // namesOfIntegers 再次成为一个类型为 [Int: String] 的空字典
908
908
```
909
909
910
910
<!--
@@ -975,7 +975,7 @@ var airports = ["YYZ": "Toronto Pearson", "DUB": "Dublin"]
975
975
976
976
``` swift
977
977
print (" The airports dictionary contains \( airports.count ) items." )
978
- // 打印 " The airports dictionary contains 2 items."
978
+ // 打印 “ The airports dictionary contains 2 items.“
979
979
```
980
980
981
981
<!--
@@ -995,7 +995,7 @@ if airports.isEmpty {
995
995
} else {
996
996
print (" The airports dictionary isn't empty." )
997
997
}
998
- // 打印 " The airports dictionary isn't empty."
998
+ // 打印 “ The airports dictionary isn't empty.“
999
999
```
1000
1000
1001
1001
<!--
@@ -1015,7 +1015,7 @@ if airports.isEmpty {
1015
1015
1016
1016
``` swift
1017
1017
airports[" LHR" ] = " London"
1018
- // airports 字典现在包含 3 个元素。
1018
+ // airports 字典现在包含 3 项
1019
1019
```
1020
1020
1021
1021
<!--
@@ -1032,7 +1032,7 @@ airports["LHR"] = "London"
1032
1032
1033
1033
``` swift
1034
1034
airports[" LHR" ] = " London Heathrow"
1035
- // “LHR”的值已更改为“London Heathrow”。
1035
+ // “LHR”的值已更改为“London Heathrow”
1036
1036
```
1037
1037
1038
1038
<!--
@@ -1053,7 +1053,7 @@ airports["LHR"] = "London Heathrow"
1053
1053
if let oldValue = airports.updateValue (" Dublin Airport" , forKey : " DUB" ) {
1054
1054
print (" The old value for DUB was \( oldValue ) ." )
1055
1055
}
1056
- // 打印 " The old value for DUB was Dublin."
1056
+ // 打印 “ The old value for DUB was Dublin.“
1057
1057
```
1058
1058
1059
1059
<!--
@@ -1075,7 +1075,7 @@ if let airportName = airports["DUB"] {
1075
1075
} else {
1076
1076
print (" That airport isn't in the airports dictionary." )
1077
1077
}
1078
- // 打印 " The name of the airport is Dublin Airport."
1078
+ // 打印 “ The name of the airport is Dublin Airport.“
1079
1079
```
1080
1080
1081
1081
<!--
@@ -1095,9 +1095,9 @@ if let airportName = airports["DUB"] {
1095
1095
1096
1096
``` swift
1097
1097
airports[" APL" ] = " Apple International"
1098
- // " Apple International" 不是APL的真实机场,所以删除它。
1098
+ // “ Apple International“ 不是APL的真实机场,所以删除它
1099
1099
airports[" APL" ] = nil
1100
- // APL 已经从字典中删除。
1100
+ // APL 已经从字典中删除
1101
1101
```
1102
1102
1103
1103
<!--
@@ -1126,7 +1126,7 @@ if let removedValue = airports.removeValue(forKey: "DUB") {
1126
1126
} else {
1127
1127
print (" The airports dictionary doesn't contain a value for DUB." )
1128
1128
}
1129
- // 打印 " The removed airport's name is Dublin Airport."
1129
+ // 打印 “ The removed airport's name is Dublin Airport.“
1130
1130
```
1131
1131
1132
1132
<!--
0 commit comments