Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a NSMutableArray.

It contains NSIndexPaths which itself a NSUInteger array.

Array looks like this

[

 (NSIndexPath xxxxxxx) 3 indexes [1, 0, 0],   
 (NSIndexPath xxxxxxx) 3 indexes [2, 1, 1],  
 (NSIndexPath xxxxxxx) 3 indexes [1, 1, 0],  
 (NSIndexPath xxxxxxx) 3 indexes [1, 0, 1],

. .

]

Now i want to sort the NSMutableArray based on NSIndexPath integer array values. And the result should be following like this.

[

(NSIndexPath xxxxxxx) 3 indexes [1, 0, 0],  
(NSIndexPath xxxxxxx) 3 indexes [1, 0, 1],   
(NSIndexPath xxxxxxx) 3 indexes [1, 1, 0],   
(NSIndexPath xxxxxxx) 3 indexes [2, 1, 1],  

..

]

How to do it?

share|improve this question
add comment

2 Answers 2

Assuming your NSMutableArray is called indexPaths, you could do:

[indexPaths sortUsingSelector:@selector(compare:)];
share|improve this answer
add comment

Other than Maddy's suggestion, you might try using a custom NSSortDescriptor that applies the specific sorting rules you want.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.