0

Hello All I need to sort an NSMutable Array that having a class Objects say Item . 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

2 Answers 2

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

[yourMutableArray sortUsingDescriptors:[NSArray arrayWithObject:descriptor]];
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks alot for a very quick response.. I did the same kind of work like [array sortUsingDescriptor:descriptor]; but its giving an exception ...
2

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.