美文网首页
iOS Model数组排序

iOS Model数组排序

作者: pingxhcn | 来源:发表于2019-05-08 20:32 被阅读0次
 // 数组排序 
    NSArray *sortResultArray = [buttonsModelArray sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {

        LessonButtonsModel * model1 = [[LessonButtonsModel alloc] initWithDictionary:obj1 error:nil];
        LessonButtonsModel * model2 = [[LessonButtonsModel alloc] initWithDictionary:obj2 error:nil];
        if ([model1.sort_order intValue] > [model2.sort_order intValue]) {
            return NSOrderedDescending;
        } else if ([model2.sort_order intValue] > [model1.sort_order intValue]) {
            return NSOrderedAscending;
        } else
            return NSOrderedAscending;
        // 升序
    }];

相关文章

网友评论

      本文标题:iOS Model数组排序

      本文链接:https://www.haomeiwen.com/subject/gcbanftx.html