Skip to content

Commit 39dbc4e

Browse files
author
Jiaolong
committed
code review
1 parent c0ff990 commit 39dbc4e

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

swift-6-beta.docc/LanguageGuide/CollectionTypes.md

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Swift 数组的类型完整写作 `Array<Element>`,其中 `Element` 是数组
4848
```swift
4949
var someInts: [Int] = []
5050
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.
5252
```
5353

5454
<!--
@@ -67,7 +67,7 @@ print("someInts is of type [Int] with \(someInts.count) items.")
6767

6868
```swift
6969
someInts.append(3)
70-
// someInts 现在包含 1 个类型为 Int 的值
70+
// someInts 现在包含 1 个类型为 Int 的值
7171
someInts = []
7272
// someInts 现在是一个空数组, 但它仍是 [Int] 类型的
7373
```
@@ -154,7 +154,7 @@ var sixDoubles = threeDoubles + anotherThreeDoubles
154154

155155
```swift
156156
var shoppingList: [String] = ["Eggs", "Milk"]
157-
// shoppingList has been initialized with two initial items
157+
// shoppingList 已经用两个初始项进行了初始化
158158
```
159159

160160
<!--
@@ -196,7 +196,7 @@ var shoppingList = ["Eggs", "Milk"]
196196

197197
```swift
198198
print("The shopping list contains \(shoppingList.count) items.")
199-
// 打印 "The shopping list contains 2 items."
199+
// 打印 The shopping list contains 2 items.
200200
```
201201

202202
<!--
@@ -216,7 +216,7 @@ if shoppingList.isEmpty {
216216
} else {
217217
print("The shopping list isn't empty.")
218218
}
219-
// 打印 "The shopping list isn't empty."
219+
// 打印 The shopping list isn't empty.
220220
```
221221

222222
<!--
@@ -236,7 +236,7 @@ if shoppingList.isEmpty {
236236

237237
```swift
238238
shoppingList.append("Flour")
239-
// shoppingList 现在包含 3 个项目,而有人正在做煎饼
239+
// shoppingList 现在包含 3 ,而有人正在做煎饼
240240
```
241241

242242
<!--
@@ -253,9 +253,9 @@ shoppingList.append("Flour")
253253

254254
```swift
255255
shoppingList += ["Baking Powder"]
256-
// shoppingList 现在包含 4 个项目
256+
// shoppingList 现在包含 4
257257
shoppingList += ["Chocolate Spread", "Cheese", "Butter"]
258-
// shoppingList 现在包含 7 个项目
258+
// shoppingList 现在包含 7
259259
```
260260

261261
<!--
@@ -275,7 +275,7 @@ shoppingList += ["Chocolate Spread", "Cheese", "Butter"]
275275

276276
```swift
277277
var firstItem = shoppingList[0]
278-
// firstItem 的值为 "Eggs"
278+
// firstItem 的值为 Eggs
279279
```
280280

281281
<!--
@@ -294,7 +294,7 @@ var firstItem = shoppingList[0]
294294

295295
```swift
296296
shoppingList[0] = "Six eggs"
297-
// the first item in the list is now equal to "Six eggs" rather than "Eggs"
297+
// 列表中的第一个项现在是 “Six eggs” 而不是 “Eggs
298298
```
299299

300300
<!--
@@ -315,11 +315,11 @@ shoppingList[0] = "Six eggs"
315315
to make that index become valid.
316316
-->
317317

318-
您还可以使用下标语法一次更改一个范围的值,即使替换值集的长度与要替换的范围不同。以下示例将`"Chocolate Spread"`, `"Cheese"``"Butter"` 替换为 `"Bananas"``"Apples"`
318+
您还可以使用下标语法一次更改一个范围的值,即使替换值集的长度与要替换的范围不同。以下示例将 `"Chocolate Spread"`, `"Cheese"``"Butter"` 替换为 `"Bananas"``"Apples"`
319319

320320
```swift
321321
shoppingList[4...6] = ["Bananas", "Apples"]
322-
// shoppingList now contains 6 items
322+
// shoppingList 现在包含 6 项
323323
```
324324

325325
<!--
@@ -336,8 +336,8 @@ shoppingList[4...6] = ["Bananas", "Apples"]
336336

337337
```swift
338338
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“ 现在是列表中的第一项
341341
```
342342

343343
<!--
@@ -358,9 +358,9 @@ shoppingList.insert("Maple Syrup", at: 0)
358358

359359
```swift
360360
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” 字符串
364364
```
365365

366366
<!--
@@ -382,7 +382,7 @@ let mapleSyrup = shoppingList.remove(at: 0)
382382

383383
```swift
384384
firstItem = shoppingList[0]
385-
// firstItem is now equal to "Six eggs"
385+
// firstItem 现在等于 “Six eggs
386386
```
387387

388388
<!--
@@ -399,9 +399,9 @@ firstItem = shoppingList[0]
399399

400400
```swift
401401
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” 字符串
405405
```
406406

407407
<!--
@@ -475,7 +475,7 @@ for (index, value) in shoppingList.enumerated() {
475475
```
476476
-->
477477

478-
有关 `for-in` 循环的更多信息,请参阅 <doc:ControlFlow#For-In-Loops>.
478+
有关 `for`-`in` 循环的更多信息,请参阅 <doc:ControlFlow#For-In-Loops>.
479479

480480
## 集合
481481

@@ -508,7 +508,7 @@ Swift 集合的类型写作 `Set<Element>`,其中 `Element` 是集合允许存
508508
```swift
509509
var letters = Set<Character>()
510510
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.
512512
```
513513

514514
<!--
@@ -527,9 +527,9 @@ print("letters is of type Set<Character> with \(letters.count) items.")
527527

528528
```swift
529529
letters.insert("a")
530-
// letters 现在包含 1 个类型为 Character 的值
530+
// letters 现在包含 1 个类型为 Character 的值
531531
letters = []
532-
// letters 现在是一个空集合,但仍然是 Set<Character> 类型
532+
// letters 现在是一个空集合,但仍然是 Set<Character> 类型
533533
```
534534

535535
<!--
@@ -552,7 +552,7 @@ letters = []
552552

553553
```swift
554554
var favoriteGenres: Set<String> = ["Rock", "Classical", "Hip hop"]
555-
// favoriteGenres 已经用三个初始元素进行了初始化
555+
// favoriteGenres 已经用三个初始元素进行了初始化
556556
```
557557

558558
<!--
@@ -592,7 +592,7 @@ var favoriteGenres: Set = ["Rock", "Classical", "Hip hop"]
592592

593593
```swift
594594
print("I have \(favoriteGenres.count) favorite music genres.")
595-
// 打印 "I have 3 favorite music genres."
595+
// 打印 I have 3 favorite music genres.
596596
```
597597

598598
<!--
@@ -613,7 +613,7 @@ if favoriteGenres.isEmpty {
613613
} else {
614614
print("I have particular music preferences.")
615615
}
616-
// 打印 "I have particular music preferences."
616+
// 打印 I have particular music preferences.
617617
```
618618

619619
<!--
@@ -633,7 +633,7 @@ if favoriteGenres.isEmpty {
633633

634634
```swift
635635
favoriteGenres.insert("Jazz")
636-
// favoriteGenres 现在包含 4 个元素
636+
// favoriteGenres 现在包含 4
637637
```
638638

639639
<!--
@@ -654,7 +654,7 @@ if let removedGenre = favoriteGenres.remove("Rock") {
654654
} else {
655655
print("I never much cared for that.")
656656
}
657-
// 打印 "Rock? I'm over it."
657+
// 打印 Rock? I'm over it.
658658
```
659659

660660
<!--
@@ -678,7 +678,7 @@ if favoriteGenres.contains("Funk") {
678678
} else {
679679
print("It's too funky in here.")
680680
}
681-
// 打印 "It's too funky in here."
681+
// 打印 It's too funky in here.
682682
```
683683

684684
<!--
@@ -808,7 +808,7 @@ oddDigits.symmetricDifference(singleDigitPrimeNumbers).sorted()
808808
Tracking bug is <rdar://problem/35301593>
809809
-->
810810

811-
### 集合成员资格与相等性
811+
### 集合成员关系与相等
812812

813813
下图描述了三个集合 --- `a``b``c`,其中重叠区域表示集合间共享的元素。集合 `a` 是集合 `b`**超集**,因为 `a` 包含了 `b` 中的所有元素。相反,集合 `b` 是集合 `a`**子集**,因为 `b` 中的所有元素都包含在 `a` 中。集合 `b` 和集合 `c`**不相交的**,因为它们没有任何共同的元素。
814814

@@ -884,7 +884,7 @@ Swift 字典的完整类型写作 `Dictionary<Key, Value>`,其中 `Key` 是可
884884

885885
```swift
886886
var namesOfIntegers: [Int: String] = [:]
887-
// namesOfIntegers 是一个空的 [Int: String] 字典
887+
// namesOfIntegers 是一个空的 [Int: String] 字典
888888
```
889889

890890
<!--
@@ -902,9 +902,9 @@ var namesOfIntegers: [Int: String] = [:]
902902

903903
```swift
904904
namesOfIntegers[16] = "sixteen"
905-
// namesOfIntegers 现在包含 1 个键值对
905+
// namesOfIntegers 现在包含 1 个键值对
906906
namesOfIntegers = [:]
907-
// namesOfIntegers 再次成为一个类型为 [Int: String] 的空字典
907+
// namesOfIntegers 再次成为一个类型为 [Int: String] 的空字典
908908
```
909909

910910
<!--
@@ -975,7 +975,7 @@ var airports = ["YYZ": "Toronto Pearson", "DUB": "Dublin"]
975975

976976
```swift
977977
print("The airports dictionary contains \(airports.count) items.")
978-
// 打印 "The airports dictionary contains 2 items."
978+
// 打印 The airports dictionary contains 2 items.
979979
```
980980

981981
<!--
@@ -995,7 +995,7 @@ if airports.isEmpty {
995995
} else {
996996
print("The airports dictionary isn't empty.")
997997
}
998-
// 打印 "The airports dictionary isn't empty."
998+
// 打印 The airports dictionary isn't empty.
999999
```
10001000

10011001
<!--
@@ -1015,7 +1015,7 @@ if airports.isEmpty {
10151015

10161016
```swift
10171017
airports["LHR"] = "London"
1018-
// airports 字典现在包含 3 个元素。
1018+
// airports 字典现在包含 3
10191019
```
10201020

10211021
<!--
@@ -1032,7 +1032,7 @@ airports["LHR"] = "London"
10321032

10331033
```swift
10341034
airports["LHR"] = "London Heathrow"
1035-
// “LHR”的值已更改为“London Heathrow”
1035+
// “LHR”的值已更改为“London Heathrow”
10361036
```
10371037

10381038
<!--
@@ -1053,7 +1053,7 @@ airports["LHR"] = "London Heathrow"
10531053
if let oldValue = airports.updateValue("Dublin Airport", forKey: "DUB") {
10541054
print("The old value for DUB was \(oldValue).")
10551055
}
1056-
// 打印 "The old value for DUB was Dublin."
1056+
// 打印 The old value for DUB was Dublin.
10571057
```
10581058

10591059
<!--
@@ -1075,7 +1075,7 @@ if let airportName = airports["DUB"] {
10751075
} else {
10761076
print("That airport isn't in the airports dictionary.")
10771077
}
1078-
// 打印 "The name of the airport is Dublin Airport."
1078+
// 打印 The name of the airport is Dublin Airport.
10791079
```
10801080

10811081
<!--
@@ -1095,9 +1095,9 @@ if let airportName = airports["DUB"] {
10951095

10961096
```swift
10971097
airports["APL"] = "Apple International"
1098-
// "Apple International" 不是APL的真实机场,所以删除它
1098+
// Apple International 不是APL的真实机场,所以删除它
10991099
airports["APL"] = nil
1100-
// APL 已经从字典中删除
1100+
// APL 已经从字典中删除
11011101
```
11021102

11031103
<!--
@@ -1126,7 +1126,7 @@ if let removedValue = airports.removeValue(forKey: "DUB") {
11261126
} else {
11271127
print("The airports dictionary doesn't contain a value for DUB.")
11281128
}
1129-
// 打印 "The removed airport's name is Dublin Airport."
1129+
// 打印 The removed airport's name is Dublin Airport.
11301130
```
11311131

11321132
<!--

0 commit comments

Comments
 (0)