I want to sort a NSMutableArray which has NSArrays with respect to the value at the index 1 of the NSArray. I’ll try to draw a picture of arrays.
NSMutableArray *ultimateHighscoreArray = {
( (NSString) userName, (double) score, (int) numOfCorrectAnswers ) ,
( John , 4.5 , 3 ) ,
( Terry , 7.5 , 1) ,
... }
The first array within the NSMutableArray is an example which shows how examples are located. Second and third are how the values actually are. So, what I want is to sort these arrays having the array containing higher value at first index to go higher up in the ranking. For this example the array that has 7.5 which is Terry Array should go before the one that has 4.5 . I want the results to be held in a NSMutableArray in decreasing order. Thank you.
This should do it:
A general advice: your data structure would be clearer if it were an array of
NSDictionaryinstances or even an array of custom objects (e.g., your customScoreclass). In those cases, you could also useNSSortDescriptorto sort the array, which would result in cleaner, easier-to-read code.