Sort an NSArray in Descending Order

前端 未结 11 1169
死守一世寂寞
死守一世寂寞 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条回答
  •  -上瘾入骨i
    2020-12-08 02:51

    If you need based on ABCD in ascending then use following code

    NSSortDescriptor *descriptor=[[NSSortDescriptor alloc] initWithKey:@"self" ascending:YES];
    NSArray *descriptors=[NSArray arrayWithObject: descriptor];
    NSArray *reverseOrder=[yourArray sortedArrayUsingDescriptors:descriptors];
    

提交回复
热议问题