- (NSComparisonResult)comparestu:(Student *)stu //排序规则
{
NSComparisonResult result = [[NSNumber numberWithInt:stu.score]compare:[NSNumber numberWithInt:self.score]]; //先按分数来排名
if (result == NSOrderedSame) { //如果分数相同 按年龄
result = [[NSNumber numberWithInt:stu.age]compare:[NSNumber numberWithInt:self.age]];
if(result == NSOrderedSame) // 如果年龄一样,就按姓名排序
{
//如果年龄相同按姓名
result = [self.name compare:stu.name];
}
}
return result;
}
|
|