我有一个NSMutableArray
包含NSURLConnection
描述,如下所示:
array {
"<NSURLConnection: 0x60eb40>",
"<NSURLConnection: 0x6030e0>",
"<NSURLConnection: 0x602ce0>",
"<NSURLConnection: 0x60c330>",
"<NSURLConnection: 0x662f5a0>",
}
我还有一个NSMutableDictionary
其键是上面的项目NSMutableArray
,如下所示:
dictionary {
"<NSURLConnection: 0x602ce0>" = "Last update: Sep 3, 2012";
"<NSURLConnection: 0x6030e0>" = "Last update: Sep 7, 2012";
"<NSURLConnection: 0x60c330>" = "Last update: Sep 4, 2012";
"<NSURLConnection: 0x60eb40>" = "Last update: Sep 6, 2012";
"<NSURLConnection: 0x662f5a0>" = "Last update: Sep 5, 2012";
}
我需要重新排序NSMutableDictionary
以匹配NSMutableArray
indexes
. 现在我正在这样做:
int a;
for (a=0; a<self.array.count; a++) {
NSString *key = [self.array objectAtIndex:a];
NSString *object = [self.dictionary objectForKey:key];
if (object !=nil) {
[self.array removeObjectAtIndex:a];
[self.array insertObject:object atIndex:a];
}
}
有没有更好的方法来重新排序NSMutableDicitioanry
以匹配 的顺序NSMutableArray
?
谢谢!