Skip to content

Instantly share code, notes, and snippets.

@tonyarnold
Created July 12, 2010 03:17
Show Gist options
  • Select an option

  • Save tonyarnold/472093 to your computer and use it in GitHub Desktop.

Select an option

Save tonyarnold/472093 to your computer and use it in GitHub Desktop.
Custom sort descriptor compare method
@interface NSString (GroupComparison)
- (NSComparisonResult)groupCompare:(NSString *)otherGroup;
@end
@implementation NSString (GroupComparison)
- (NSComparisonResult)groupCompare:(NSString *)otherGroup {
NSArray *orderedGroups = [NSArray arrayWithObjects:HSGeneralShortcutGroup, HSChangeSpaceWithoutDirectionShortcutGroup, HSChangeSpaceWithDirectionShortcutGroup, HSIndividualSpaceShortcutGroup, HSAddRemoveSpacesShortcutGroup, nil];
NSUInteger selfGroupIndex = [orderedGroups indexOfObject:self];
NSUInteger otherGroupIndex = [orderedGroups indexOfObject:otherGroup];
if (selfGroupIndex < otherGroupIndex) {
return NSOrderedAscending;
} else if (selfGroupIndex > otherGroupIndex) {
return NSOrderedDescending;
} else {
return NSOrderedSame;
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment