I want to sort alphabetically the NSMutableArray and add an object to the beginning of array.
For example :
NSMutableArray *myArray = [[NSMutableArray alloc] initWithObjects:@"Red",@"Blue",@"Green",nil];
I want in return myarray = “blue”,”green”,Red”;
and then I have to add “multicolor” option at the beginning of array.
So myarray becomes: “multicolor”,”blue”,”green”,Red”;
Or if it is possible to sort array without disturbing the “multicolor” option (which will be at the first place), this could also be acceptable.
Thanks.
Use one of the
sort*methods to sort the array.Use
insertObject:atIndex:with index0to insert at the beginning of the array.Details can be found here:
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html