Question

I have an NSMutableArray with this values:

how, format, anderson, babilon,

I would like to know if there is a command in which you can arrange this array in alphabetical order, so that the end result of the array becomes this:

anderson, babilon, format, how

observation -> my example above 4 items are specified in an array, but actually this array can store more than 1000 items, Someone can help me?

Was it helpful?

Solution

I would like to know if there is a command in which you can arrange this array in alphabetical order, so that the end result of the array becomes...

Yes. If you look at the NSMutableArray documentation you'll find a list of methods that can be used for sorting. They all start with the word "sort".

Apple also provides documentation on sorting arrays in the section named Sorting Arrays in Collection Programming Topics. For example, you could use the method -sortUsingSelector: this way:

NSMutableArray *names = [@[@"how", @"anderson", @"format", @"babilon"] mutableCopy];
[names sortUsingSelector:@selector(compare:)];        
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top