根据model里面的时间字段进行排序
- (NSArray *)sortedArrayUsingComparatorByPaymentTimeWithDataArr:(NSArray *)dataArr{
NSArray *sortArray = [dataArr sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
BillInfoModel *model1 = obj1;
BillInfoModel *model2 = obj2;
//还款时间
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat: @"yyyy-MM-dd"];
NSDate *date1= [dateFormatter dateFromString:model1.nextRepaymentDate];
NSDate *date2= [dateFormatter dateFromString:model2.nextRepaymentDate];
if (date1 == [date1 earlierDate: date2]) { //不使用intValue比较无效
return NSOrderedDescending;//降序
}else if (date1 == [date1 laterDate: date2]) {
return NSOrderedAscending;//升序
}else{
return NSOrderedSame;//相等
}
}];
return sortArray;
}