#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
//将字典的key从Z->A排序,按排序后的key的顺序,输出value,将value按字符串输出
NSDictionary *[email protected]{@"R":@"e",
@"T":@"e",
@"D":@"b",
@"S":@"u",
@"K":@"a",
@"A":@"s",
@"O":@" ",
@"N":@"p",
@"B":@"b",
@"J":@"u",
@"F":@" ",
@"U":@"t",
@"H":@"l",
@"E":@"j",
@"Z":@"s",};
NSArray *arr=[dict allKeys];
NSComparator comp=^(id obj1,id obj2){
NSComparisonResult result=[obj2 compare:obj1];
return result;
};
NSArray *sortArr=[arr sortedArrayUsingComparator:comp];
for(NSString *str in sortArr) {
NSLog(@"key=%@,value=%@",str,dict[str]);
}
}
return 0;
}