-1

Possible Duplicate:
How to sort a NSArray alphabetically?

Hey I've looked all over this site and google for the answer to my question. I'm very new to iPhone programming and I'm figuring this question should be fairly easy to answer. In my app, I have an array that is filled with strings. I display the array in a UITableView with each string in its own cell. However, the strings are placed in a non-organized manner. Is there a way to organize an array's strings by alphabetizing the strings? ANY help is GREATLY appreciated. Thanks in advance.

Community
  • 1
  • 1
Bryman
  • 37
  • 5
  • Have you checked [this question](http://stackoverflow.com/questions/1351182/how-to-sort-a-nsarray-alphabetically)? – Bert Dec 24 '12 at 00:01
  • Hey thanks for the response. I have checked that and the solution given in that question does not work in my program. I get an error saying it is because my array is an NSMutableArray and not just an NSArray. – Bryman Dec 24 '12 at 00:07
  • Post the code. As written, the question @Bert referred you to should work. That it doesn't means that something else is going on. – bbum Dec 24 '12 at 00:10
  • If there is some code then it shouldn't be closed, but you had to specify it. – Ramy Al Zuhouri Dec 24 '12 at 00:12
  • @RamyAlZuhouri The close requests are because, as written, the question is an exact duplicate of the question Bert linked to. – bbum Dec 24 '12 at 00:13
  • I know this and one of these two votes is mine.But before reading that he has some code and it doesn't work.If he posts the code we might reconsider it. – Ramy Al Zuhouri Dec 24 '12 at 00:15
  • Thanks guys for the responses and I realized I should have specified as to which type of array I was using in the first place. I apologize for the poor wording. I used bbum's answer and I fixed my problem. Thank you all though! – Bryman Dec 24 '12 at 00:20

1 Answers1

2

In the future, post the code you having trouble with. Your question is too vague to answer, as written. But your comment fills in enough information to imply that you are trying to sort a mutable array.

For that, you can use any of the NSMutableArray sorting methods;

– sortUsingDescriptors:
– sortUsingComparator:
– sortWithOptions:usingComparator:
– sortUsingFunction:context:
– sortUsingSelector:

Take your pick as any one of them will sort the array itself (and not produce a new array).

bbum
  • 162,346
  • 23
  • 271
  • 359
  • Alright thanks for the feedback. Sorry about the unclear question. These options you posted helped a lot! Thanks! – Bryman Dec 24 '12 at 00:18