Cerve86
Cerve86

Reputation: 3

how to sort an NSArray with a nested NSArray

Hi I'm new with the Objective-C and i try to do some try. I have an NSArray called "values". It is an array of array. It seems like :

["0" = > "aString",6872,5523,0091]

["1" = > "anotherString",4422,1234,0091]

["2" = > "aString",6812,2143,0314] ...

How do I sort the "values" array than the first integer value? I should use the NSPredicate ? please help me with some example. thanks

Upvotes: 0

Views: 715

Answers (1)

Benoît
Benoît

Reputation: 7427

Something like that with block (assuming that your integer value are NSNumber or some class that can be compared):

NSArray *sortArray = [yourArray sortedArrayUsingComparator: ^(id elt1, id elt2) {
    return [[elt1 objectAtIndex:1] compare:[elt2 objectAtIndex:1]];
    } ];

Upvotes: 3

Related Questions