How do I sort an NSMutableArray with custom objects in it?

Compare method Either you implement a compare-method for your object: – (NSComparisonResult)compare:(Person *)otherObject { return [self.birthDate compare:otherObject.birthDate]; } NSArray *sortedArray = [drinkDetails sortedArrayUsingSelector:@selector(compare:)]; NSSortDescriptor (better) or usually even better: NSSortDescriptor *sortDescriptor; sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@”birthDate” ascending:YES]; NSArray *sortedArray = [drinkDetails sortedArrayUsingDescriptors:@[sortDescriptor]]; You can easily sort by multiple keys by adding more than one to … Read more