我有兩個NSArray
對象,我希望排序相同。一個包含NSString
對象,另一個自定義Attribute
對象。這是我的「鑰匙」的NSArray的樣子:根據另一個字符串NSArray的排序對自定義對象排序NSArray
// The master order
NSArray *stringOrder = [NSArray arrayWithObjects:@"12", @"10", @"2", nil];
的NSArray中使用自定義對象:
// The array of custom Attribute objects that I want sorted by the stringOrder array
NSMutableArray *items = [[NSMutableArray alloc] init];
Attribute *attribute = nil;
attribute = [[Attribute alloc] init];
attribute.assetID = @"10";
[items addObject:attribute];
attribute = [[Attribute alloc] init];
attribute.assetID = @"12";
[items addObject:attribute];
attribute = [[Attribute alloc] init];
attribute.assetID = @"2";
[items addObject:attribute];
所以,我想作的就是用stringOrder
陣列,以確定的排序定製對象數組。 我該怎麼做?
這似乎並不像使用數組的好地方。字典或有序字典可能更合適,也更容易。 – Alexander