oc-sort-系统方法

 NSMutableArray *sortarr = [NSMutableArray arrayWithObjects:@"23",@"23",@"43",@"4",@"5",@"6",@"7",@"8",@"9", nil];
    [sortarr sortUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
        NSInteger obj1Value = [obj1 integerValue];
        NSInteger obj2Value = [obj2 integerValue];
        
        /*
        if (obj1Value > obj2Value) {
            return NSOrderedAscending;
        }else if (obj1Value < obj2Value){
            return NSOrderedDescending;
        }
        return NSOrderedSame;//大到小
        */
        if (obj1Value < obj2Value) {
            return NSOrderedAscending;
        }else if (obj1Value > obj2Value){
            return NSOrderedDescending;
        }
        return NSOrderedSame;//小到大
    }];

在iOS开发中,使用这个系统的排序算法是最好不过的,比自己写的那些强百倍···

你可能感兴趣的:(iOS知识点,oc排序,sort)