zoukankan      html  css  js  c++  java
  • OC对数组排序的方法

    方法一: 使用sortUsingSelector

    如: [_cards sortUsingSelector:@selector(isSortByContactName:)];

    [_cards sortUsingSelector:@selector(isSortBYPhoneNumber:)];

    -(BOOL)isSortByContactName:(Card *)aCard
    {
        if ([_contactName compare:[aCard contactName]] ==NSOrderedDescending) {
            return YES;
        }
        return NO;
    }
    -(BOOL)isSortBYPhoneNumber:(Card *)aCard
    {
        if (_phoneNum>[aCard phoneNum]) {
            return YES;
        }
        return NO;
    }

    方法二: sortedArrayUsingComparator:

     _seatInfoArray = [_seatInfoArray sortedArrayUsingComparator:^NSComparisonResult(SeatInfoModel *obj1, SeatInfoModel *obj2) {
                NSTimeInterval time1 = obj1.end_unixtime.doubleValue;
                NSTimeInterval time2 = obj2.end_unixtime.doubleValue;
                if (time1<time2) {
                    return NSOrderedAscending;
                }
                else
                {
                    return NSOrderedDescending;
                }
            }];


    方法三:

     NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"createTime" ascending:YES];

     [_array sortUsingDescriptors:[NSArray arrayWithObject:sort]];

  • 相关阅读:
    MATLAB 简单多边形的核
    MATLAB Moravec算子
    MATLAB Sepia Tone滤镜
    MATLAB 异或分类
    MATLAB 神经网络分类
    MATLAB 地图上画经纬度
    MATLAB 最小二乘多项式拟合
    MATLAB 对应点集配准的四元数法
    MATLAB 高斯牛顿法最优化
    MATLAB Levenberg-Marquardt法最优化
  • 原文地址:https://www.cnblogs.com/liaods/p/4788657.html
Copyright © 2011-2022 走看看