TRStudent*stu1 = [TRStudentstudentWithName:@"张三"andAge:18];
TRStudent*stu2 = [TRStudentstudentWithName:@"李四"andAge:20];
TRStudent*stu3 = [TRStudentstudentWithName:@"王五"andAge:19];
TRStudent*stu4 = [TRStudentstudentWithName:@"赵六"andAge:22];
TRStudent*stu5 = [TRStudentstudentWithName:@"钱七"andAge:21];
NSArray*stu =@[stu1,stu2,stu3,stu4,stu5];
NSArray*sorted = [stusortedArrayUsingComparator:^NSComparisonResult(idobj1,idobj2) {
NSNumber*obj1Age = [NSNumbernumberWithInt:[obj1age]];
NSNumber*obj2Age = [NSNumbernumberWithInt:[obj2age]];
return[obj1Agecompare:obj2Age];
}];
for(TRStudent*sinsorted)
{
NSLog(@"%@", s);
}
NSDictionary*dict =@{@"1":stu1,@"2":stu2,@"3":stu3,@"4":stu4,@"5":stu5};
sorted = [dictkeysSortedByValueUsingComparator:^NSComparisonResult(idobj1,idobj2) {
NSNumber*obj1Age = [NSNumbernumberWithInt:[obj1age]];
NSNumber*obj2Age = [NSNumbernumberWithInt:[obj2age]];
return[obj1Agecompare:obj2Age];
}];
for(NSString*keyinsorted)
{
NSLog(@"%@=%@", key, dict[key]);
}