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]];

  • 相关阅读:
    Python异常处理
    Python 线程、进程和协程
    python版本升级及pip部署方法
    Python socket编程
    循环遍历方法笔记
    TCP/IP协议分为哪四层,具体作用是什么。
    Python Paramiko模块与MySQL数据库操作
    Python面向对象编程(二)
    h5专题常用小代码
    sethc问题
  • 原文地址:https://www.cnblogs.com/liaods/p/4788657.html
Copyright © 2011-2022 走看看