用了几分钟做的简单翻译
一个例子
直接贴代码,不过多解释
class imageFile {
var fileName = String()
var fileID = Int()
}
//使用
var images : [imageFile] = []
images.sort({ $0.fileID > $1.fileID })
下面是闭包的进阶使用
images.sort({ (image1: imageFile, image2: imageFile) -> Bool in return image1.fileID > image2.fileID })
images.sort({ image1, image2 in return image1.fileID > image2.fileID })
images.sort({ image1, image2 in image1.fileID > image2.fileID })
images.sort({ $0.fileID > $1.fileID })
images = images.sorted({ (image1: imageFile, image2: imageFile) -> Bool in return image1.fileID > image2.fileID })
images = images.sorted({ image1, image2 in return image1.fileID > image2.fileID })
images = images.sorted({ image1, image2 in image1.fileID > image2.fileID })
images = images.sorted({ $0.fileID > $1.fileID })
sort(&images, { (image1: imageFile, image2: imageFile) -> Bool in return image1.fileID > image2.fileID })
sort(&images, { image1, image2 in return image1.fileID > image2.fileID })
sort(&images, { image1, image2 in image1.fileID > image2.fileID })
sort(&images, { $0.fileID > $1.fileID })
images = sorted(images, { (image1: imageFile, image2: imageFile) -> Bool in return image1.fileID > image2.fileID })
images = sorted(images, { image1, image2 in return image1.fileID > image2.fileID })
images = sorted(images, { image1, image2 in image1.fileID > image2.fileID })
images = sorted(images, { $0.fileID > $1.fileID })
let dictionary = [
"A" : [1, 2],
"Z" : [3, 4],
"D" : [5, 6]
]
NSDictionary根据key排序
let sortedKeys = Array(dictionary.keys).sorted(<) // ["A", "D", "Z"]
let sortedKeysAndValues = sorted(dictionary) { $0.0 < $1.0 }
println(sortedKeysAndValues) // [(A, [1, 2]), (D, [5, 6]), (Z, [3, 4])]
|
请发表评论