zoukankan      html  css  js  c++  java
  • NSArray,NSMutableArray的三种排序

    int main(int argc, const char * argv[]) {
        @autoreleasepool {
            //字符串进行排序
            NSArray *arr=@[@"b",@"a",@"c"];
            NSSortDescriptor *ns=[NSSortDescriptor sortDescriptorWithKey:nil ascending:YES];
            NSArray *B=[arr sortedArrayUsingDescriptors:@[ns]];
            NSLog(@"%@",B);
            
            //代码块排序
          NSArray *a=  [arr sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
                return [obj1 compare:obj2];
          }];
            NSLog(@"%@",a);
            //选择器排序
            NSArray *C=[arr sortedArrayUsingSelector:@selector(compare:)];
            NSLog(@"%@",C);
            
        }
        return 0;
    }
       //可变集合的排序
            NSMutableArray *arr=[NSMutableArray array];
            [arr addObject:@"v"];
            [arr addObject:@"b"];
            [arr addObject:@"A"];
            //选择器排序
            [arr sortUsingSelector:@selector(compare:)];
            NSLog(@"%@",arr);
            //代码块排序
            [arr sortUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
                return [obj1 compare:obj2];
            }];
            NSLog(@"%@",arr);
            //描述信息排序
            NSSortDescriptor *nsSort=[NSSortDescriptor sortDescriptorWithKey:nil ascending:YES];
            [arr sortUsingDescriptors:@[nsSort]];
            NSLog(@"%@",arr);
  • 相关阅读:
    Java修饰符
    java中接口的定义
    抽象类
    final关键字的特点
    hdu6489 2018 黑龙江省大学生程序设计竞赛j题
    POJ 3268 (dijkstra变形)
    poj 2253 floyd最短路
    poj1681 Network
    bzoj1202 狡猾的商人
    Nastya Is Buying Lunch
  • 原文地址:https://www.cnblogs.com/qianLL/p/5118616.html
Copyright © 2011-2022 走看看