I am getting some post from Facebook for my application, I have all post data into a dictionary and that dictionary is in array. Now I have the post time from the Facebook which is in dictionary as string. I want to sort that array according to latest post which is known by the post time. I had seen several answers on SO but they did in a single dictionary I want to do that from different dictionary.
This is my array of dictionary from which I have to sort array according to dictionary postTime value.
Code:
var dateFormatter: NSDateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
var tempArray: NSMutableArray = NSMutableArray()
for var i = 0; i < dicts.count; i++ {
var dic: NSMutableDictionary = dicts[i] as! NSMutableDictionary
let dateConverted: NSDate = dateFormatter.dateFromString(dic["postTime"] as! String)!
dic["postTime"] = dateConverted
tempArray.addObject(dic)
}
var descriptor: NSSortDescriptor = NSSortDescriptor(key: "postTime", ascending: true)
var descriptors: NSArray = [descriptor]
var sortedArray: NSArray = tempArray.sortedArrayUsingDescriptors(descriptors as! [NSSortDescriptor])
NSLog("%@", sortedArray)
dicts is my array of dictionary and i have to take the post time which is seen in the image.