How to sort numbers in NSArray?

前端 未结 5 853
深忆病人
深忆病人 2021-02-03 11:55

I can\'t piece together how to do this.

I fetch my array from a plist, this array is full of numbers (as set in the plist). Now al I need to do is sort them so they are

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-03 12:38

    The following will sort the numbers in ascending order and then reverse the result to give the numbers in descending order:

    NSArray *sorted = [[[array sortedArrayUsingSelector:@selector(compare:)] reverseObjectEnumerator] allObjects];
    

    This previous question has some other alternatives: Sort an NSArray in Descending Order

提交回复
热议问题