2010-06-21 113 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?

若要返回一個單獨的數組,你很可能需要創建您當前的副本數組然後有一個排序。然後你會有兩個,你的原件和你的副本是排序的。