Created
July 12, 2010 03:17
-
-
Save tonyarnold/472093 to your computer and use it in GitHub Desktop.
Custom sort descriptor compare method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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