KStudent studentWithAge:10 andName:@"LUSON"];
JKStudent *student3 = [JKStudent studentWithAge:13 andName:@"EASON"];
JKStudent *student4 = [JKStudent studentWithAge:12 andName:@"LINA"];
JKStudent *student5 = [JKStudent studentWithAge:11 andName:@"KATU"];
//初始数组
NSArray *studentArray1 = [NSArray arrayWithObjects:student1,student2,student3,student4,student5, nil];
NSLog(@"初始数组:%@",studentArray1);
//按照年龄排序
NSArray *studentArray2 = [studentArray1 sortedArrayUsingSelector:@selector(compare:)];
NSLog(@"按照年龄排序:%@",studentArray2);
//按照名字排序
NSArray *studentArray3 = [studentArray1 sortedArrayUsingSelector:@selector(compareName:)];
NSLog(@"按照名字排序:%@",studentArray3);
//按照先年龄再名字排序
NSArray *studentArray4 = [studentArray1 sortedArrayUsingSelector:@selector(compareAgeAndName:)];
NSLog(@"按照先年龄再名字排序:%@",studentArray4);
|