I'm trying to sort an array of dictionaries in Swift. My structure is like this:
[
[
"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"
]
]
I'm trying to sort the array by each "Timestamp" value in each dictionary. How can I do this?
My current code (not working) is:
self.todayArray.sortInPlace {item1,item2 in
let date1 = Int("\(item1["Timestamp"])")
let date2 = Int("\(item2["Timestamp"])")
return date1 > date2
}
return Double(item1["Timestamp"]!) < Double(item2["Timestamp"]!)instead.