int main(int argc, const char * argv[]) {
@autoreleasepool {
NSArray *array = @[CreateDict(@"王思聪", 27, YES),
CreateDict(@"范冰冰", 35, NO),
CreateDict(@"马云", 51, YES),
CreateDict(@"霍建华", 36, YES),
CreateDict(@"赵丽颖", 28, NO)];
//第1题 请按照年龄的升序排序输出,输出样式为:王思聪,男性,今年27岁
NSSortDescriptor *ageWithSort=[[NSSortDescriptor alloc]initWithKey:kAge ascending:YES];
NSArray *elementarr=[NSArray arrayWithObjects:ageWithSort,nil];
NSArray *sortArray=[array sortedArrayUsingDescriptors:elementarr];
NSLog(@"第一题");
NSLog(@"排序后:");
for (NSDictionary *dic in sortArray) {
int i=[dic[@"gender"]intValue];
if (i==1) {
NSString *str=@"男性";
NSLog(@"%@,%@,今年%@岁",dic[kName],str,dic[kAge]);
}
if (i==0) {
NSString *str1=@"女性";
NSLog(@"%@,%@,今年%@岁",dic[kName],str1,dic[kAge]);
}
}