我正在嘗試對Swift中的字典數組進行排序。我的結構是這樣的:在Swift中對字符串字典進行排序
[
[
"DateTime": "8/16/16, 4:00 PM",
"Owner": "Teacher1",
"Subject": "AP Euro",
"Address": "Mr. Hughes\' Room",
"Type": "Final",
"Timestamp": "2016081616009498",
"Location": "On Campus",
"Duration": "50 min",
"Members": "ownerKey,1,107434,109431"
],
[
"DateTime": "7/29/16, 6:35 AM",
"Owner": "109431",
"Subject": "Algebra 2 Acc",
"Address": "Library",
"Type": "Quiz",
"Timestamp": "2016072906356642",
"Location": "On Campus",
"Duration": "5 min",
"Members": "ownerKey"
]
]
我想在每個字典中的每個「Timestamp
」價值排序的數組。我怎樣才能做到這一點?
我當前的代碼(不工作)是:
self.todayArray.sortInPlace {item1,item2 in
let date1 = Int("\(item1["Timestamp"])")
let date2 = Int("\(item2["Timestamp"])")
return date1 > date2
}
你的時間戳可能是一個32位整數太大。使用'return Double(item1 [「Timestamp」]!)