Sort an NSArray in Descending Order

前端 未结 11 1225
死守一世寂寞
死守一世寂寞 2020-12-08 02:23

I have an NSArray of NSNumber objects that I have successfully sorted in ascending order using the following:

[myArray sortedArrayU         


        
11条回答
  •  情话喂你
    2020-12-08 02:52

    use sortarrayusingcomparator method like that

    NSArray *sortedArray = [array sortedArrayUsingComparator:
    ^NSComparisonResult(id obj1, id obj2){
            return [obj2 compare:obj1];
        }];
    

    by reversing the order of objects you will obtain a descending order

提交回复
热议问题