0

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.

1 Answer 1

1

Use a NSSortDescriptor

[fetchRequest setSortDescriptors: [NSArray arrayWithObject:
                                       [[[NSSortDescriptor alloc] initWithKey:@"score"
                                                                    ascending:YES] autorelease]]];
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, thats an easy way to do it - thank you really much :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.