在nsmutable数组中排序 [英] Sorting in nsmutable array
本文介绍了在nsmutable数组中排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我的游戏中有以下数据.我已经在cocos2d中开发了游戏.
Suppose I have following data in my game. I have developed game in cocos2d.
Name Score
Sagar 10000
Amit 2000
Vishal 90
以上数据存储在plist文件中.
Above data is stored in plist file.
Plist的根目录为数组.
Plist has an array as root.
其中有10个字典.
每个字典都有两个值:
- 字符串值-名称
- 数字值-得分
当我使用
NSMutableArray *x=[[NSMutableArray alloc] initWithContentsOfFile:@"Sagar.plist"];
我想按分数对可变数组进行排序.
I want to sort this mutable array by score.
有可能吗?
推荐答案
使用排序描述符:
NSSortDescriptor * sortByScore = [[[NSSortDescriptor alloc] initWithKey:@"Score" ascending:NO] autorelease];
NSArray * descriptors = [NSArray arrayWithObject:sortByScore];
NSArray * sorted = [x sortedArrayUsingDescriptors:descriptors];
这篇关于在nsmutable数组中排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文