NSArray排序

1.NSArray排序

  • Foundation自带类排序
NSArray *arr = @[@(1), @(9), @(5), @(2)];
NSArray *newArr = [arr sortedArrayUsingSelector:@selector(compare:)];
  • 自定义类排序
    NSArray *arr = @[p1, p2, p3, p4, p5];
    //    默认按照升序排序
    NSArray *newArr = [arr sortedArrayWithOptions:NSSortConcurrent usingComparator:^NSComparisonResult(Person *obj1, Person *obj2) {
        return obj1.age > obj2.age;
    }];
    NSLog(@"%@", newArr);

 

posted @ 2017-03-28 21:00  iFat  阅读(196)  评论(0编辑  收藏  举报