I have an array of dictionaries. Within each dictionary, there is a a key dateOfInfo
(an NSDate
) and several other things. I want to sort the array
try like this,
NSDateFormatter *fmtDate = [[NSDateFormatter alloc] init];
[fmtDate setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
NSComparator compareDates = ^(id string1, id string2)
{
NSDate *date1 = [fmtDate dateFromString:string1];
NSDate *date2 = [fmtDate dateFromString:string2];
return [date1 compare:date2];
};
NSSortDescriptor * sortDesc1 = [[NSSortDescriptor alloc] initWithKey:@"StartTime" ascending:YES comparator:compareDates];
[youArray sortUsingDescriptors:@[sortDesc1]];