I found these code snippets from answers on Stack Overflow, neither elegantly solving my problem.
The first piece of code from “Sorting array in alphabetic order…” gave no warnings but was followed by a crash.
NSSortDescriptor *nameSort = [NSSortDescriptor sortDescriptorWithKey:@"Name" ascending:YES];
[myArray sortUsingDescriptors:[NSArray arrayWithObject:nameSort]];
While the second piece of code generates a warning per use in my code but generates the results I want:
myMutableArray = [myMutableArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
So, my question is why does the second method work with the warning, “Incompatible pointer types assigning to 'NSMutableArray*' from incompatible type 'NSArray*'“?
If you’re trying to do an in-place sort of an NSMutableArray, you should use
sortUsingSelector:rather than reassigning the result ofsortedArrayUsingSelector:(which is declared to be a plain NSArray, not an NSMutableArray).