2

Possible Duplicate:
NSDictionary keys sorted by value numerically?

I'm maintaining the scores of my game in a dictionary. Key will be the name of the user and value will be the score. When displaying the scores in table view, I want to sort the dictionary depending on values so that first item will be top score and last item will be least score. How can this be done?

Community
  • 1
  • 1
Satyam
  • 15,493
  • 31
  • 131
  • 244

1 Answers1

2

try this one

NSSortDescriptor *descriptor = 
    [[NSSortDescriptor alloc] initWithKey:@"Score" ascending:YES];
[items sortUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];
[descriptor release];
casperOne
  • 73,706
  • 19
  • 184
  • 253
B25Dec
  • 2,301
  • 5
  • 31
  • 54