iOS基础学习

Objective-C基础学习之NSArray排序

2017-10-24  本文已影响8人  WenJim
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);
上一篇下一篇

猜你喜欢

热点阅读