Ios – How to sort strings in NSMutableArray into alphabetical order


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 that?

Best Solution

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

sortedArray = [anArray sortedArrayUsingSelector:

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:)];