Would it be possible for someone to make a tutorial on how to sort a date which is inside mutable a开发者_StackOverflow社区rray of dictionaries ?
Assume your NSDate object is in a dictionary with @"DateKey" key.
NSInteger dateSort(id dict1, id dict2, void* context){
return [[dict1 objectForKey:@"DateKey"] compare:[dict2 objectForKey:@"DateKey"]];
}
[dateArray sortUsingFunction:dateSort context:NULL];
Or iOS 4 solution:
[dateArray sortUsingComparator:(NSComparator)^(id obj1, id obj2){
return [[obj1 objectForKey:@"DateKey"] compare:[obj1 objectForKey:@"DateKey"]];
}];
The following line should sort NSMutableArray containing NSDate objects:
[dateArray sortUsingSelector:@selector(compare:)];
精彩评论