我有一系列带有键和值的词典。我需要根据日期格式降序排序一系列字典,比如formate 2016-09-02 12:25:08。
答案 0 :(得分:0)
以下是按日期排序ArrayOfDictionary的可能解决方案:
let sortedRostersByDate = TempArray.sortedArray(comparator: { (obj1, obj2) -> ComparisonResult in
var date2:NSDate!
var date1:NSDate!
if let dict = obj2 as? NSDictionary
{
if let tempdate2 = df.date(from: dict.object(forKey: "Sectiontitle") as! String)
{
date2 = tempdate2 as NSDate!
}
}
if let dict = obj1 as? NSDictionary
{
if let tempdate1 = df.date(from: dict.object(forKey: "Sectiontitle") as! String)
{
date1 = tempdate1 as NSDate!
}
}
return date2.compare(date1 as Date)
})
let SortedArray = NSMutableArray(array: sortedRostersByDate)
这里TempArray是要排序的数组