Would it be possible for someone to make a tutorial on how to sort a date which is inside mutable array of dictionaries ?
A:
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:)];
Vladimir
2010-08-16 10:28:04
The OP appears to be sorting an `NSMutableArray` of `NSDictionary` objects, each containing an `NSDate`. A custom comparison method is required.
Justin
2010-08-16 10:30:18
@Justin, thanks, read the question too fast and missed its point.
Vladimir
2010-08-16 10:54:41
Thanks vladimir
Hardik Patel
2010-08-30 08:31:12