如何像这样排序字典[[Strnig:AnyOBject]]

时间:2016-02-02 17:56:04

标签: ios iphone swift sorting dictionary

我有这种词典:

var data = [[String : AnyObject]]()

data = [["name" : "Alex", "time" : 11.1], ["name" : "Igor", "time" : 2.0], ["name: Tomas" : "time" : 8.88]]

现在我想按最佳时间排序。我知道如何在简单的数组中做到这一点,但在这本词典中我有一个问题。有人可以帮助我吗?

1 个答案:

答案 0 :(得分:-1)

您可以使用此

data.sortInPlace { (obj1, obj2) -> Bool in
    guard let time1 = obj1["time"] as? Float else {return false}
    guard let time2 = obj2["time"] as? Float else {return false}
    return time1 < time2
}