数组内装有V3HealthModel,依靠model的startTime属性将数组重新排序
一:
NSMutableArray *returnArray = [NSMutableArray array];
NSComparator cmptr = ^(id obj1, id obj2){
if ([((V3HealthModel *)obj1) startTime] < [((V3HealthModel *)obj2) startTime]) {
return (NSComparisonResult)NSOrderedDescending;
}
else
{
return (NSComparisonResult)NSOrderedAscending;
}
};
NSLog(@"%ld %ld",((V3HealthModel *)[healthArray firstObject]).startTime,((V3HealthModel *)[healthArray lastObject]).startTime);
[returnArray addObjectsFromArray:[healthArray sortedArrayUsingComparator:cmptr]];
二:
NSArray *sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"startTime" ascending:NO]];
[healthArray sortUsingDescriptors:sortDescriptors];