I have to sort an array of objects by a property of the objects that is a string. How can I do this?
For just sorting array of strings:
sorted = [array sortedArrayUsingSelector:@selector(compare:)];
For sorting objects with key "name":
NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES selector:@selector(compare:)];
sorted = [array sortedArrayUsingDescriptors:@[sort]];
Also, instead of compare: you can use:
caseInsensitiveCompare:
localizedCaseInsensitiveCompare: