Sort an NSArray in Descending Order

前端 未结 11 1231
死守一世寂寞
死守一世寂寞 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 03:03

    Use the following code to sort Array on the basis of key on which you want to sort tge array (e.g name , code, address,emp_id etc...)

    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Enter Sort Type" ascending:NO];
    
    NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
    return [array sortedArrayUsingDescriptors:sortDescriptors];
    

提交回复
热议问题