Swift 2.0:排序而不是排序函数

时间:2015-09-22 07:25:21

标签: swift sorting

我有(在swift 1中)这行代码:

keys = sorted(namesDict!.allKeys as! [String])

但不再支持函数排序(Swift 2.0)。 我可以写什么来对键进行排序?

谢谢!

1 个答案:

答案 0 :(得分:1)

我想你已回答了自己的问题。 sort函数返回一个已排序的数组,您可以将其存储在变量中。

let dict = ["b":1, "a":2, "c":3]
let sortedKeys = dict.keys.sort() //returns ["a", "b", "c"]