How to sort an NSMutableArray List of names in alphabetical order in Objective-C?

Madan Mohan picture Madan Mohan · Apr 16, 2010 · Viewed 9.2k times · Source

I need to display the list of names which I am getting from the parser. I am getting the NSMutable arrary of list, then i need to display them in alphabetical order.

I tried doing what is given as:

NSArray *myArtistArray=[[NSArray alloc]init];
myArtistArray=[artistsList sortUsingSelector:@selector(compare:) ];

// error void value not ignored as it outght to be
[myArtistArray sortedArrayUsingSelector:@selector(compare:)];

Answer

drawnonward picture drawnonward · Apr 16, 2010
[yourMutableArray sortUsingSelector:@selector(compare:)];
[yourArray sortedArrayUsingSelector:@selector(compare:)];