[示例]NSDictionary-字典中的数据转到数组,排序后输出
代码:
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { NSDictionary *dic1=@{@"1-1":@"02", @"1-2":@"11", @"1-3":@"89", @"1-4":@"70"}; NSArray *arr1=[dic1 allValues]; //字典中所有数据存入数组 for (id str in arr1){ NSLog(@"%@",str); } //按value排序数组 arr1=[arr1 sortedArrayUsingComparator:^NSComparisonResult(id obj1,id obj2) { return [obj1 compare:obj2]; }]; for (id str in arr1){ NSLog(@"%@",str); } } return 0; }