Reputation: 265
I've a problem sorting an nsarray. The nsarray is filled with core data:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"ReactionInfo" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSError *error;
self.scoreInfos_arr = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
for (ReactionInfo *info in self.scoreInfos_arr) {
debug(@"%@ - %f",info.player,info.score);
}
U see that I get the player name and the score. My target is, to show the scores in a table view, but of course they should be sort numeric.
I didn't find a solution on how to sort this NSArray (self.scoreInfos_arr is it)
I hope somebody can help me.
Upvotes: 0
Views: 206
Reputation: 26972
Use a NSSortDescriptor
[fetchRequest setSortDescriptors: [NSArray arrayWithObject:
[[[NSSortDescriptor alloc] initWithKey:@"score"
ascending:YES] autorelease]]];
Upvotes: 1