我有(在swift 1中)这行代码:
keys = sorted(namesDict!.allKeys as! [String])
但不再支持函数排序(Swift 2.0)。 我可以写什么来对键进行排序?
谢谢!
答案 0 :(得分:1)
我想你已回答了自己的问题。 sort
函数返回一个已排序的数组,您可以将其存储在变量中。
let dict = ["b":1, "a":2, "c":3]
let sortedKeys = dict.keys.sort() //returns ["a", "b", "c"]