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,012
  • 30
  • 127
  • 238

1 Answers1

2

try this one

NSSortDescriptor *descriptor = 
    [[NSSortDescriptor alloc] initWithKey:@"Score" ascending:YES];
[items sortUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];
[descriptor release];
casperOne
  • 72,334
  • 18
  • 180
  • 242
B25Dec
  • 2,073
  • 3
  • 29
  • 50