Created
May 2, 2012 08:31
-
-
Save taylanpince/2575090 to your computer and use it in GitHub Desktop.
NSArray reorder
This file contains 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
static NSInteger compareListingTypesAccordingToStaticOrder(ListingType *type1, ListingType *type2, void *context) { | |
static NSArray *orderedTypes = nil; | |
if (orderedTypes == nil) { | |
orderedTypes = [[NSArray alloc] initWithObjects: | |
@"Everything", @"Restaurants", @"Bars", | |
@"Cafes", @"Bakeries", @"Fashion Stores", | |
@"Design Stores", @"Bookstores", @"Art Galleries", | |
@"Fitness Clubs", @"Grocery", @"Hotels", @"Services", nil]; | |
} | |
NSInteger order1 = [orderedTypes indexOfObject:type1.categoryTitle]; | |
NSInteger order2 = [orderedTypes indexOfObject:type2.categoryTitle]; | |
if (order1 < order2) { | |
return (order1 == NSNotFound) ? NSOrderedDescending : NSOrderedAscending; | |
} else if (order1 > order2) { | |
return (order2 == NSNotFound) ? NSOrderedAscending : NSOrderedDescending; | |
} else { | |
return NSOrderedSame; | |
} | |
} | |
[listingTypes sortUsingFunction:compareListingTypesAccordingToStaticOrder context:NULL]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment