NSArray 排序

先研究一种方法

        NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:0];
        for (int i = 0; i < 10; i++) {
            int a = arc4random()%100;
            [array addObject:@(a)];
        }
        
        NSArray *sortedArray = [array sortedArrayUsingComparator:^NSComparisonResult(NSNumber *obj1,NSNumber *obj2) {
            if ([obj1 intValue] > [obj2 intValue]) {
                return NSOrderedDescending;
            }
            return (NSComparisonResult)NSOrderedAscending;
        }];
    NSLog(@"%@", sortedArray);

 

posted @ 2015-08-08 16:17  孤光一点莹  阅读(115)  评论(0编辑  收藏  举报