开发者

sort a date which is inside mutable array of dictionaries

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜