开发者

how to sort an NSMutable Array reference to date in iphone

开发者 https://www.devze.com 2023-01-08 13:04 出处:网络
Hello All I need to sort an NSMutable Array that having a class Objects say I开发者_Go百科tem . Item class have date,url,link,title,guid etc .. I am storing this Object Into an NsMutableArray each tim

Hello All I need to sort an NSMutable Array that having a class Objects say I开发者_Go百科tem . Item class have date,url,link,title,guid etc .. I am storing this Object Into an NsMutableArray each time. so MyArray will have number Of Item class Objects .. now I need to sort Myarray using date attribute . Can any one tell me the way. Thanks


NSSortDescriptor *descriptor = [NSSortDescriptor withKey:@"date" ascending:YES]; // or NO, if you want descending

[yourMutableArray sortUsingDescriptors:[NSArray arrayWithObject:descriptor]];


If MyArray only holds NSDate* Objects then:

NSArray* mySortedArray = [MyArray sortedArrayUsingSelector:@selector(compare:)]

This will call the following method on your NSDate objects.

- (NSComparisonResult)compare:(NSNumber *)aNumber
0

精彩评论

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