Skip to content

Commit 773f990

Browse files
committedJun 15, 2014
fix 2.4 collection types

File tree

2 files changed

+72
-65
lines changed

2 files changed

+72
-65
lines changed
 

‎source/README.md

+56-39
Original file line numberDiff line numberDiff line change
@@ -27,42 +27,59 @@ lifedim说他平时12点就会睡,1点47分,发给我校对后的文档。
2727

2828
全体人员名单(排名不分先后):
2929

30-
- numbbbbb
31-
- coverxit
32-
- wh1100717
33-
- TimothyYe
34-
- honghaoz
35-
- Hawstein
36-
- JaySurplus
37-
- stanzhai
38-
- lyuka
39-
- geek5nan
40-
- xielingwang
41-
- yankuangshi
42-
- dabing1022
43-
- siemenliu
44-
- fd5788
45-
- youkugems
46-
- haolloyin
47-
- superkam
48-
- vclwei
49-
- sg552
50-
- bzsy
51-
- pyanfield
52-
- ericzyh
53-
- 088haizi
54-
- viztor
55-
- pp-prog
56-
- baocaixiong
57-
- marsprince
58-
- shinyzhu
59-
- happyming
60-
- menlongsheng
61-
- zq54zquan
62-
- Evilcome
63-
- lslxdx
64-
- yeahdongcn
65-
- zqp
66-
- xiehurricane
67-
- Jasonbroker
68-
- aquaporcus
30+
- [numbbbbb](https://github.com/numbbbbb)
31+
- [stanzhai](https://github.com/stanzhai)
32+
- [coverxit](https://github.com/coverxit)
33+
- [wh1100717](https://github.com/wh1100717)
34+
- [TimothyYe](https://github.com/TimothyYe)
35+
- [honghaoz](https://github.com/honghaoz)
36+
- [lyuka](https://github.com/lyuka)
37+
- [JaySurplus](https://github.com/JaySurplus)
38+
- [Hawstein](https://github.com/Hawstein)
39+
- [geek5nan](https://github.com/geek5nan)
40+
- [yankuangshi](https://github.com/yankuangshi)
41+
- [xielingwang](https://github.com/xielingwang)
42+
- [yulingtianxia](https://github.com/yulingtianxia)
43+
- [twlkyao](https://github.com/twlkyao)
44+
- [dabing1022](https://github.com/dabing1022)
45+
- [vclwei](https://github.com/vclwei)
46+
- [fd5788](https://github.com/fd5788)
47+
- [siemenliu](https://github.com/siemenliu)
48+
- [youkugems](https://github.com/youkugems)
49+
- [haolloyin](https://github.com/haolloyin)
50+
- [wxstars](https://github.com/wxstars)
51+
- [IceskYsl](https://github.com/IceskYsl)
52+
- [sg552](https://github.com/sg552)
53+
- [superkam](https://github.com/superkam)
54+
- [zac1st1k](https://github.com/zac1st1k)
55+
- [bzsy](https://github.com/bzsy)
56+
- [pyanfield](https://github.com/pyanfield)
57+
- [ericzyh](https://github.com/ericzyh)
58+
- [peiyucn](https://github.com/peiyucn)
59+
- [sunfiled](https://github.com/sunfiled)
60+
- [lzw120](https://github.com/lzw120)
61+
- [viztor](https://github.com/viztor)
62+
- [wongzigii](https://github.com/wongzigii)
63+
- [umcsdon](https://github.com/umcsdon)
64+
- [zq54zquan](https://github.com/zq54zquan)
65+
- [xiehurricane](https://github.com/xiehurricane)
66+
- [Jasonbroker](https://github.com/Jasonbroker)
67+
- [tualatrix](https://github.com/tualatrix)
68+
- [pp-prog](https://github.com/pp-prog)
69+
- [088haizi](https://github.com/088haizi)
70+
- [baocaixiong](https://github.com/baocaixiong)
71+
- [yeahdongcn](https://github.com/yeahdongcn)
72+
- [shinyzhu](https://github.com/shinyzhu)
73+
- [lslxdx](https://github.com/lslxdx)
74+
- [Evilcome](https://github.com/Evilcome)
75+
- [zqp](https://github.com/zqp)
76+
- [NicePiao](https://github.com/NicePiao)
77+
- [LunaticM](https://github.com/LunaticM)
78+
- [menlongsheng](https://github.com/menlongsheng)
79+
- [lifedim](https://github.com/lifedim)
80+
- [happyming](https://github.com/happyming)
81+
- [bruce0505](https://github.com/bruce0505)
82+
- [Lin-H](https://github.com/Lin-H)
83+
- [takalard](https://github.com/takalard)
84+
- [ChildhoodAndy](https://github.com/ChildhoodAndy)
85+
- [marsprince](https://github.com/marsprince)

‎source/chapter2/04_Collection_Types.md

+16-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
> 翻译:zqp
2-
> 校对:shinyzhu
1+
> 翻译:zqp
2+
> 校对:shinyzhu, stanzhai
33
44
# 集合类型 (Collection Types)
55
-----------------
@@ -14,7 +14,7 @@ Swift 语言提供经典的数组和字典两种集合类型来存储集合数
1414

1515
Swift 语言里的数组和字典中存储的数据值类型必须明确。 这意味着我们不能把不正确的数据类型插入其中。 同时这也说明我们完全可以对获取出的值类型非常自信。 Swift 对显式类型集合的使用确保了我们的代码对工作所需要的类型非常清楚,也让我们在开发中可以早早地找到任何的类型不匹配错误。
1616

17-
> 注意:
17+
> 注意:
1818
Swift 的数组结构在被声明成常量和变量或者被传入函数与方法中时会相对于其他类型展现出不同的特性。 获取更多信息请参见[集合的可变性](#mutability_of_collections)[集合在赋值和复制中的行为](09_Classes_and_Structures.html#assignment_and_copy_behavior_for_collection_types)章节。
1919

2020
<a name="arrays"></a>
@@ -44,8 +44,8 @@ var shoppingList: String[] = ["Eggs", "Milk"]
4444

4545
`shoppingList`变量被声明为“字符串值类型的数组“,记作`String[]`。 因为这个数组被规定只有`String`一种数据结构,所以只有`String`类型可以在其中被存取。 在这里,`shoppinglist`数组由两个`String`值(`"Eggs"``"Milk"`)构造,并且由字面量定义。
4646

47-
> 注意:
48-
> `Shoppinglist`数组被声明为变量(`var`关键字创建)而不是常量(`let`创建)是因为以后可能会有更多的数据项被插入其中。
47+
> 注意:
48+
> `Shoppinglist`数组被声明为变量(`var`关键字创建)而不是常量(`let`创建)是因为以后可能会有更多的数据项被插入其中。
4949
5050
在这个例子中,字面量仅仅包含两个`String`值。匹配了该数组的变量声明(只能包含`String`的数组),所以这个字面量的分配过程就是允许用两个初始项来构造`shoppinglist`
5151

@@ -123,14 +123,8 @@ shoppingList[4...6] = ["Bananas", "Apples"]
123123
// shoppingList 现在有六项
124124
```
125125

126-
<<<<<<< HEAD
127-
> 注意:
128-
>我们不能使用下标语法在数组尾部添加新项。如果我们试着用这种方法对索引越界的数据进行检索或者设置新值的操作,我们会引发一个运行期错误。我们可以使用索引值和数组的`count`属性进行比较来在使用某个索引之前先检验是否有效。除了当`count`等于 0 时(说明这是个空数组),最大索引值一直是`count - 1`,因为数组都是零起索引。
129-
=======
130-
> 注意:
131-
>
132-
>我们不能使用下标语法在数组尾部添加新项。如果我们试着用这种方法对索引越界的数据进行检索或者设置新值的操作,我们会引发一个运行时错误。我们可以使用索引值和数组的`count`属性进行比较来在使用某个索引之前先检验是否有效。除了当`count`等于 0 时(说明这是个空数组),最大索引值一直是`count - 1`,因为数组都是零起索引。
133-
>>>>>>> a516af6a531a104ec88da0d236ecf389a5ec72af
126+
> 注意:
127+
>我们不能使用下标语法在数组尾部添加新项。如果我们试着用这种方法对索引越界的数据进行检索或者设置新值的操作,我们会引发一个运行期错误。我们可以使用索引值和数组的`count`属性进行比较来在使用某个索引之前先检验是否有效。除了当`count`等于 0 时(说明这是个空数组),最大索引值一直是`count - 1`,因为数组都是零起索引。
134128
135129
调用数组的`insert(atIndex:)`方法来在某个具体索引值之前添加数据项:
136130

@@ -271,8 +265,8 @@ var airports: Dictionary<String, String> = ["TYO": "Tokyo", "DUB": "Dublin"]
271265

272266
`airports`字典被定义为一种`Dictionary<String, String>`,它意味着这个字典的键和值都是`String`类型。
273267

274-
> 注意:
275-
> `airports`字典被声明为变量(用`var`关键字)而不是常量(`let`关键字)因为后来更多的机场信息会被添加到这个示例字典中。
268+
> 注意:
269+
> `airports`字典被声明为变量(用`var`关键字)而不是常量(`let`关键字)因为后来更多的机场信息会被添加到这个示例字典中。
276270
277271
`airports`字典使用字典字面量初始化,包含两个键值对。第一对的键是`TYO`,值是`Tokyo`。第二对的键是`DUB`,值是`Dublin`
278272

@@ -364,6 +358,7 @@ for (airportCode, airportName) in airports {
364358
// TYO: Tokyo
365359
// LHR: London Heathrow
366360
```
361+
367362
`for-in`循环请参见[For 循环](05_Control_Flow.html#for_loops)
368363

369364
我们也可以通过访问它的`keys`或者`values`属性(都是可遍历集合)检索一个字典的键或者值:
@@ -374,9 +369,7 @@ for airportCode in airports.keys {
374369
}
375370
// Airport code: TYO
376371
// Airport code: LHR
377-
```
378372

379-
```swift
380373
for airportName in airports.values {
381374
println("Airport name: \(airportName)")
382375
}
@@ -389,15 +382,13 @@ for airportName in airports.values {
389382
```swift
390383
let airportCodes = Array(airports.keys)
391384
// airportCodes is ["TYO", "LHR"]
392-
```
393385

394-
```swift
395386
let airportNames = Array(airports.values)
396387
// airportNames is ["Tokyo", "London Heathrow"]
397388
```
398389

399-
> 注意:
400-
> Swift 的字典类型是无序集合类型。其中字典键,值,键值对在遍历的时候会重新排列,而且其中顺序是不固定的。
390+
> 注意:
391+
> Swift 的字典类型是无序集合类型。其中字典键,值,键值对在遍历的时候会重新排列,而且其中顺序是不固定的。
401392
402393
<a name="creating_an_empty_dictionary"></a>
403394
### 创建一个空字典
@@ -420,8 +411,8 @@ namesOfIntegers = [:]
420411
// namesOfIntegers 又成为了一个 Int, String类型的空字典
421412
```
422413

423-
> 注意:
424-
> 在后台,Swift 的数组和字典都是由泛型集合来实现的,想了解更多泛型和集合信息请参见[泛型](22_Generics.html)
414+
> 注意:
415+
> 在后台,Swift 的数组和字典都是由泛型集合来实现的,想了解更多泛型和集合信息请参见[泛型](22_Generics.html)
425416
426417
<a name="mutability_of_collections"></a>
427418
## 集合的可变性
@@ -433,6 +424,5 @@ namesOfIntegers = [:]
433424

434425
Swift 数组的可变性行为同时影响了数组实例如何被分配和修改,想获取更多信息,请参见[集合在赋值和复制中的行为](09_Classes_and_Structures.html#assignment_and_copy_behavior_for_collection_types)
435426

436-
> 注意:
437-
> 在我们不需要改变数组大小的时候创建不可变数组是很好的习惯。如此 Swift 编译器可以优化我们创建的集合。
438-
427+
> 注意:
428+
> 在我们不需要改变数组大小的时候创建不可变数组是很好的习惯。如此 Swift 编译器可以优化我们创建的集合。

0 commit comments

Comments
 (0)
Please sign in to comment.