tags:

views:

51

answers:

1

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
The OP appears to be sorting an `NSMutableArray` of `NSDictionary` objects, each containing an `NSDate`. A custom comparison method is required.
Justin
@Justin, thanks, read the question too fast and missed its point.
Vladimir
Thanks vladimir
Hardik Patel