I have and array of custom objects of Person Class
Person : NSObject{
NSString *firstName;
NSString *lastName;
NSString *age;
}
NSMutableArray
A Drop in code to help you doing it,
-(NSMutableArray *)sortArray:(NSArray *)arrayTosort withKey:(NSString *)key ascending:(BOOL)_ascending
{
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:key
ascending:_ascending] ;
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
return [[arrayTosort sortedArrayUsingDescriptors:sortDescriptors] mutableCopy];
}
here key is key
or keypath
.