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

  • 相关阅读:
    js 设计模式
    jquery 概述
    Node.js最新Web技术栈(2015年5月)
    this
    gulp
    bootstrap modal
    jsTree问题
    iterm2 学习笔记
    knowledge_map 修改笔记
    handsontable 问题
  • 原文地址:https://www.cnblogs.com/liaods/p/4788657.html
Copyright © 2011-2022 走看看