Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Suppose I have following data in my game. I have developed game in cocos2d.

Name    Score
Sagar   10000
Amit     2000
Vishal     90

Above data is stored in plist file.

Plist has an array as root.

Within that there are 10 dictionary.

Each dictionary has two values:

  • String values - Name
  • Number value - score

When I use

NSMutableArray *x=[[NSMutableArray alloc] initWithContentsOfFile:@"Sagar.plist"];

I want to sort this mutable array by score.

Is it possible?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
984 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use a sort descriptor:

NSSortDescriptor * sortByScore = [[[NSSortDescriptor alloc] initWithKey:@"Score" ascending:NO] autorelease];
NSArray * descriptors = [NSArray arrayWithObject:sortByScore];
NSArray * sorted = [x sortedArrayUsingDescriptors:descriptors];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...