I have this code which works on numbers (distance) which allows me to sort by closest to farthest. However I would like to do something similar but instead sort alphabetically. So I need to sort self.names alphabetically essentially. Also, I’d like to eventually sort self.names alphabetically and if you have identical names then sort those by distance. Is this possible?
- (NSComparisonResult)sortByDistFromVor:(radiostations *)anObject
{
if ([self.distFromVor doubleValue] < [anObject.distFromVor doubleValue]) {
return NSOrderedAscending;
} else if ([self.distFromVor doubleValue] > [anObject.distFromVor doubleValue]) {
return NSOrderedDescending;
}
return NSOrderedSame;
}
String implements a comparison, so the radiostations class (whose name ought to be capitalized by convention) can implement it’s name comparison like this:
And to get a secondary sort as you described: