How to sort an NSMutableArray List of names in alphabetical order in Objective-C?
I need to display the list of names which I am getting from the parser. I am getting the NSMu开发者_如何学Pythontable 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:)];
[yourMutableArray sortUsingSelector:@selector(compare:)];
[yourArray sortedArrayUsingSelector:@selector(compare:)];
[yourMutableArray sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
NSArray *arraysort=[[NSArray alloc] initWithObjects:@"z",@"v",@"a",@"g",@"b", nil];
NSArray *sortedArray = [arraysort sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
for (NSString *str in sortedArray) {
NSLog(@"string %@ ",str);
}
NSLog(@"sortedarrayelements %d",[sortedArray count]);
[yourArrayName sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
精彩评论