Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I sort an NSMutableArray alphabetically?

Tags:

I want to sort an NSMutableArray alphabetically.

like image 451
Ali Avatar asked Jan 18 '11 11:01

Ali


People also ask

How do I sort NSArray?

NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]; sortedArray=[anArray sortedArrayUsingDescriptors:@[sort]]; Your objects will be sorted according to the name property of those objects.

Is NSMutableArray ordered?

The answer is yes, the order of the elements of an array will be maintained - because an array is an ordered collection of items, just like a string is an ordered sequence of characters...

What is NSMutableArray Objective C?

The NSMutableArray class declares the programmatic interface to objects that manage a modifiable array of objects. This class adds insertion and deletion operations to the basic array-handling behavior inherited from NSArray . NSMutableArray is “toll-free bridged” with its Core Foundation counterpart, CFMutableArray .

How do I create an NSArray in Objective C?

Creating NSArray Objects Using Array Literals In addition to the provided initializers, such as initWithObjects: , you can create an NSArray object using an array literal. In Objective-C, the compiler generates code that makes an underlying call to the init(objects:count:) method.


1 Answers

You can do this to sort NSMutableArray:

[yourArray sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; 
like image 62
Mobile Developer iOS Android Avatar answered Sep 21 '22 13:09

Mobile Developer iOS Android