如何对包含自定义元素类型的NSMutableArray排序
//JSDataModel.h文件
@interface JSDataModel:NSObject
@property(nonatomic,copy) NSString *userName;
@property(nonatomic,copy) NSString *sortNum;
@end
//初始化数据
NSMutableArray *tempArray = [NSMutableArray array];
for (NSUInteger i =5; i>0; i--) {
JSDataModel *model = [[JSDataModel alloc]init];
model.userName = @"userName";
model.sortNum = [@(i) stringValue];
[tempArray addObject:model];
}
//对对象数组中的所有元素排除
NSSortDescriptor *sorter = [[NSSortDescriptor alloc]initWithKey:@"sortNum" ascending:YES];
NSArray *temp = [tempArray sortedArrayUsingDescriptors:@[sorter]];//排序后的数组
NSLog(@"%@",temp);