I've been following along the More iPhone Development book, and in the section on Core Data they make use of a protocol which dictates how to display different data types as NSString.
Code:
@protocol SettingsValueDisplay
- (NSString *)settingsValueDisplay;
@end
@interface NSString (SettingsValueDisplay) <SettingsValueDisplay>
- (NSString *)settingsValueDisplay;
@end
@interface NSDate (SettingsValueDisplay) <SettingsValueDisplay>
- (NSString *)settingsValueDisplay;
@end
//and so on....
Code:
@implementation NSString (SettingsValueDisplay)
- (NSString *)settingsValueDisplay {
return self;
}
@end
#pragma mark -
#pragma mark NSDate SettingsValueDisplay
@implementation NSDate (SettingsValueDisplay)
- (NSString *)settingsValueDisplay {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSString *returnVal = [dateFormatter stringFromDate:self];
[dateFormatter release];
return returnVal;
}
//and so on...
@end
I'm attempting to modify this code to suit more of my own needs but I've run into a problem with BOOL. Is it possible to create something similar for BOOLs, or will I treat those as exceptions when I use
Code:
[self.managedObject valueForKey:@"key"] settingsValueDisplay];
in my table views.
Any help is greatly appreciated.