To sort an NSMutableArray with custom objects, you can either implement a compare-method for your object:
- (NSComparisonResult)compare:(id)otherObject {
return [self.birthDate compare:otherObject];
}
NSArray *sortedArray;
sortedArray = [drinkDetails sortedArrayUsingSelector:@selector(compare:)];
or even better: (The default sorting selector of NSSortDescriptor is compare:)
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"birthDate"
ascending:YES] autorelease];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *sortedArray;
sortedArray = [drinkDetails sortedArrayUsingDescriptors:sortDescriptors];
int myInt = (int) myFloat;