-7

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?

user3372120
  • 134
  • 1
  • 10
  • 3
    Yes. There is such a command. – RobP Apr 09 '14 at 18:55
  • 1
    Please read the docs for `NSArray` and `NSMutableArray`. – rmaddy Apr 09 '14 at 18:55
  • checkout this answer http://stackoverflow.com/questions/1351182/how-to-sort-a-nsarray-alphabetically – rockstarr Apr 09 '14 at 18:56
  • 2
    possible duplicate of [How can I sort an NSMutableArray alphabetically?](http://stackoverflow.com/questions/4723697/how-can-i-sort-an-nsmutablearray-alphabetically) and http://stackoverflow.com/questions/6315323/how-can-i-sort-strings-in-nsmutablearray-into-alphabetical-order?rq=1 and http://stackoverflow.com/questions/13498624/sorting-nsmutablearrays-alphabetically?rq=1 – rmaddy Apr 09 '14 at 19:00
  • 3
    FYI - as you type a question, SO shows you related questions that may already answer your question. Please always check them before submitting your question. – rmaddy Apr 09 '14 at 19:02

1 Answers1

1

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:)];        
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
Caleb
  • 124,013
  • 19
  • 183
  • 272