开发者

sort a date which is inside mutable array of dictionaries

开发者 https://www.devze.com 2023-01-11 13:17 出处:网络
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 @\"Da

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:)];
0

精彩评论

暂无评论...
验证码 换一张
取 消