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
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]];
} ];
精彩评论