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