29 Mar 2019

Swift-字典-按Key排序和按Value排序

陆子旭

利用闭包,非常黑科技。

let dict = ["27":"w","15":"t","36":"b"]
let keys = dict.sorted(by: {$0.0 < $1.0})
let values = dict.sorted(by: {$0.1 < $1.1})
print(keys)
print(values)

参考


Tags:
0 comments