Created
January 9, 2015 02:34
-
-
Save weekwood/cecddac97008407b3d13 to your computer and use it in GitHub Desktop.
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
static NSDictionary *titleMapping = nil; | |
if (!titleMapping) { | |
NSString *(^const format)(NSUInteger, NSString *, NSString *) = ^(NSUInteger value, NSString *singular, NSString *plural) { | |
return [NSString stringWithFormat:@"%d %@", value, (value == 1 ? singular : plural)]; | |
}; | |
titleMapping = @{ | |
@"Scratches" : ^(MyClass *target) { | |
return format([target numberOfScratches], @"Scratch", @"Scratches"); | |
}, | |
@"Dents" : ^(MyClass *target) { | |
return format([target numberOfDents], @"Dent", @"Dents"); | |
}, | |
@"Painted Panels" : ^(MyClass *target) { | |
return format([target numberOfPaintedPanels], @"Painted Panel", @"Painted Panels"); | |
}, | |
@"Chips" : ^(MyClass *target) { | |
return format([target numberOfChips], @"Chip", @"Chips"); | |
}, | |
@"Tires" : ^(MyClass *target) { | |
return format([target numberOfTires], @"Tire", @"Tires"); | |
} | |
}; | |
} | |
NSString *(^getTitle)(MyClass *target) = titleMapping[title]; | |
return getTitle ? getTitle(self) : nil; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment