How can I sort an NSMutableArray alphabetically?

后端 未结 6 721
迷失自我
迷失自我 2020-12-08 05:17

I want to sort an NSMutableArray alphabetically.

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 05:36

    NSSortDescriptor *valueDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES]; // Describe the Key value using which you want to sort. 
    NSArray * descriptors = [NSArray arrayWithObject:valueDescriptor]; // Add the value of the descriptor to array.
    sortedArrayWithName = [yourDataArray sortedArrayUsingDescriptors:descriptors]; // Now Sort the Array using descriptor.
    

    Here you will get the sorted array list.

提交回复
热议问题