【发布时间】:2012-11-20 09:02:04
【问题描述】:
我有两个 NSArray 对象,我希望它们的排序相同。一个包含NSString 对象,另一个包含自定义Attribute 对象。这是我的“关键” 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 数组来确定items 自定义对象数组的排序。
我该怎么做?
【问题讨论】:
-
这似乎不是使用数组的好地方。字典或有序字典可能更合适,也更容易。
标签: objective-c ios nsmutablearray nsarray