2010-06-21 116 views
0
阵列

我的应用程序有3种对象:A,B和C中的每个对象由字典表示这样的:iphone - 排序字典

NSDictionary *oneObject = [NSDictionary dictionaryWithObjectsAndKeys: 
    [NSNumber numberWithInt:i], @"number", 
    [NSString stringWithString:@"A", @"kind", //this can be A, B or C 
    [NSNumber numberWithBool:YES], @"used", // YES or NO 
    [NSString stringWithString:oneName, @"name", 
    nil]; 

对象像存储像阵列上这个:

NSMutableArray *listOfObjects = [NSMutableArray arrayWithObjects: 
    oneObject1, oneObject2 ..etc.. , nil]; 

所以,我有一个可变的字典数组。

现在我想这个排序可变数组,获得一个新的数组以下列顺序

1) all objects A 
2) all objects B 
3) all objects C 

所有对象都在他们的类别进行分类...像

object A, apple 
object A, banana 
object A, orange 
object B, car 
object B, donkey 
object B, phone 
object B, zebra 
object C, ant 
object C, box 
object C, cigar 
object C, hotel 
object C, lamb 

我的意思是,每个类别都按对象名称排序,但整个数组按类别排序。

我该怎么做? 感谢您的任何帮助。

回答

1

用同样的方法在这里你可以修改你的比较功能做你需要的东西:

How to sort an NSMutableArray with custom objects in it?

若要返回一个单独的数组,你很可能需要创建您当前的副本数组然后有一个排序。然后你会有两个,你的原件和你的副本是排序的。