I am aware that there is a lot of questions about this topic, and i do apologize for that as i just cant get this to work for my NSMutableArray. I have problem to really understand the sorting and i have been reading documentation
I have an NSMutableArray with the following type of data:
Player name
score
Player name
score
Player name
score
...
It is a combination between a name and a score (NSNumber). I am trying to find a way to sort this based on the score. I have read a lot but i just do not get this to work, i also have problem to understand the sort concept. I have tried to sort the full array but...
I would very much appreciate if someone can give me a short, understandable, explanation of the sort scenario for this and also an example of how to sort this.
Edit: I changed to dictionary, selected the values and was thinking to sort the allObjects (stored as NSNumber in the dict) and then just select the key from the dict based on the sorted object.
NSArray *allPlayers = [playerResultInTheGame allKeys];
NSArray *allObjects = [playerResultInTheGame allValues];
NSLog(@"allPlayers: %@", allPlayers);
NSLog(@"allObjects: %@", allObjects);
NSMutableArray *sortedArray = [allObjects sortedArrayUsingSelector:@selector(Compare:)];
I get the following when i run this:
2011-01-16 21:10:08.417 XX[6640:207] playerResultInTheGame: {
Barnspelare = 3;
Vuxenspelare = 3;
}
2011-01-16 21:10:08.418 XX[6640:207] allPlayers: (
Barnspelare,
Vuxenspelare
)
2011-01-16 21:10:08.418 XX[6640:207] allObjects: (
3,
3
)
2011-01-16 21:10:08.419 XX[6640:207] -[NSCFNumber Compare:]: unrecognized selector sent to instance 0x5b26f10
2011-01-16 21:10:08.422 XX[6640:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFNumber Compare:]: unrecognized selector sent to instance 0x5b26f10'
Can someone please advice as i do not really understand this?