From 0779f979ac71cb840ddd73a4740e5fdeca05b602 Mon Sep 17 00:00:00 2001 From: chenyc Date: Tue, 21 Jul 2015 17:34:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=9B=86=E5=90=88=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=9C=A8Swift=202.0=20sort=E6=96=B9=E6=B3=95=E7=9A=84?= =?UTF-8?q?=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/chapter2/04_Collection_Types.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/source/chapter2/04_Collection_Types.md b/source/chapter2/04_Collection_Types.md index 21db0b85..c8795de5 100755 --- a/source/chapter2/04_Collection_Types.md +++ b/source/chapter2/04_Collection_Types.md @@ -35,7 +35,7 @@ Swift 的`Arrays`、`Sets`和`Dictionaries`类型被实现为泛型集合。更 > 注意: Swift 的`Array`类型被桥接到`Foundation`中的`NSArray`类。 - 更多关于在`Foundation`和`Cocoa`中使用`Array`的信息,参见 *Using Swift with Cocoa and Obejective-C* 一书。 + 更多关于在`Foundation`和`Cocoa`中使用`Array`的信息,参见 *Using Swift with Cocoa and Obejective-C* 一书。 ### 数组的简单语法 @@ -395,10 +395,10 @@ for genre in favoriteGenres { 更多关于`for-in`循环信息,参见[For循环](05_Control_Flow.html#for_loops)。 -Swift 的`Set`类型没有确定的顺序,为了按照特定顺序来遍历一个`Set`中值可以使用`sorted()`方法,它将根据提供的序列返回一个排序的集合. +Swift 的`Set`类型没有确定的顺序,为了按照特定顺序来遍历一个`Set`中值可以使用`sort()`方法,它将根据提供的序列返回一个排序的集合. ```swift -for genre in sorted(favoriteGenres) { +for genre in favoriteGenres.sort() { print("\(genre)") } // prints "Classical" @@ -427,13 +427,13 @@ for genre in sorted(favoriteGenres) { let oddDigits: Set = [1, 3, 5, 7, 9] let evenDigits: Set = [0, 2, 4, 6, 8] let singleDigitPrimeNumbers: Set = [2, 3, 5, 7] -sorted(oddDigits.union(evenDigits)) +oddDigits.union(evenDigits).sort() // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] -sorted(oddDigits.intersect(evenDigits)) +oddDigits.intersect(evenDigits).sort() // [] -sorted(oddDigits.subtract(singleDigitPrimeNumbers)) +oddDigits.subtract(singleDigitPrimeNumbers).sort() // [1, 9] -sorted(oddDigits.exclusiveOr(singleDigitPrimeNumbers)) +oddDigits.exclusiveOr(singleDigitPrimeNumbers).sort() // [1, 2, 9] ```