Here's how I do it in my Person class:
This line does the sort in the NSMutableArray containing Person objects:
Code:
[array sortUsingSelector:@selector(compareFullCommaName:)];
This method is implemented in the Person class:
Code:
-(NSComparisonResult)compareFullCommaName:(MPerson*)inPerson
{
NSString* selfCommaName = [self textForField:kPersonFullNameComma];
NSString* otherPersonCommaName = [inPerson textForField:kPersonFullNameComma];
return [selfCommaName compare:otherPersonCommaName];
}
The full comma names are 'lastname, firstname' but you get the idea. You need a comparison method that returns an appropriate NSComparisonResult. Look at the docs for sortUsingSelector:
BTW, answers to basic Cocoa/Foundation questions like this can be found on Cocoabuilder.com. See for instance
http://www.cocoabuilder.com/search/a...rds=sort+array