对500多条消息数据排序 用如下耗时函数打印耗时...
NSDate* tmpStartData = [NSDate date];
doubledeltaTime = [[NSDatedate]timeIntervalSinceDate:tmpStartData];
NSLog(@"ssssssssssssss cost time = %f", deltaTime);
```
//排序一
-(NSArray*)sortArrayWith:(NSArray*)arry{
NSArray* sortArry=[arry sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
Message* model_1 = (Message*)obj1;
Message* model_2 = (Message*)obj2;
NSDate*date1 = [selfreadTimeStr:model_1.createTime];
NSDate*date2 = [selfreadTimeStr:model_2.createTime];
if( [date1timeIntervalSinceNow] < [date2timeIntervalSinceNow]) {
returnNSOrderedAscending;
}else{
returnNSOrderedDescending;
}
}];
returnsortArry;
}
//排序二
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"createTime" ascending:YES];
NSArray *sortArray = [NSArray arrayWithObjects:descriptor,nil];
NSMutableArray* allMsgs = [allMessage sortedArrayUsingDescriptors:sortArray].mutableCopy;
总结: 第一种方法慎用