美文网首页
复杂数组排序

复杂数组排序

作者: 夜之海澜 | 来源:发表于2020-03-12 17:00 被阅读0次

    SFBankListItemModel为数组中的对象,以该对象中的某个属性进行排序

    //对数据按次数排序 降序
      NSArray *sortArrays = [userCards sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
            SFBankListItemModel *model1 = (SFBankListItemModel *)obj1;
            SFBankListItemModel *model2 = (SFBankListItemModel *)obj2;
            NSNumber *num1 = [NSNumber numberWithUnsignedLongLong:[model1.cardInfo.createTime longLongValue]];
            NSNumber *num2 = [NSNumber numberWithUnsignedLongLong:[model2.cardInfo.createTime longLongValue]];
           return [num2 compare:num1];
                            
       }];
    

    [num2 compare:num1]降序,
    [num2 compare:num1]升序

    相关文章

      网友评论

          本文标题:复杂数组排序

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