1
我必須按照升序或降序對以下數組對象進行排序。iPhone應用程序中的NSDictionary數組的排序
NSArray *keys = [NSArray arrayWithObjects:@"key1", @"key2", @"key3",
@"key4", @"key5", nil];
NSArray *objects = [NSArray arrayWithObjects:@"0", @"2", @"1",
@"5", @"0", nil];
NSDictionary* dictionary = [NSDictionary dictionaryWithObjects:objects
forKeys:keys];
for (id key in [dictionary allKeys]) {
NSLog(@"key: %@, value: %@", key, [dictionary objectForKey:key]);
}
我的輸出應該是這樣的。
key: key4, value:5
key: key2, value:2
key: key3, value:1
key: key1, value:0
key: key5, value:0
'for(id key in [dictionary allKeys]){...}'。 – 2011-07-17 12:21:32