how to sort an NSMutable Array reference to date in iphone
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
精彩评论