How can I sort strings in NSMutableArray into alphabetical order?

后端 未结 4 712
暖寄归人
暖寄归人 2020-12-24 11:26

I have a list of strings in an NSMutableArray, and I want to sort them into alphabetical order before displaying them in my table view.

How can I do tha

4条回答
  •  猫巷女王i
    2020-12-24 11:59

    There is the following Apple's working example, using sortedArrayUsingSelector: and localizedCaseInsensitiveCompare: in the Collections Documentation:

    sortedArray = [anArray sortedArrayUsingSelector:
                           @selector(localizedCaseInsensitiveCompare:)];
    

    Note that this will return a new sorted array. If you want to sort your NSMutableArray in place, then use sortUsingSelector: instead, like so:

    [mutableArray sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
    

提交回复
热议问题