Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-09-2010, 12:08 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 10
cnewbs is on a distinguished road
Default Displaying BOOL as String

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.
cnewbs is offline   Reply With Quote
Old 07-09-2010, 07:58 AM   #2 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Brooklyn
Posts: 6
TheDoty is on a distinguished road
Default

In your .h:

Code:
@interface BOOL (SettingsValueDisplay) <SettingsValueDisplay>
- (NSString *)settingsValueDisplay;
@end

And in your .m:

Code:
@implementation BOOL (SettingsValueDisplay)
- (NSString *)settingsValueDisplay {
	if(self) {
             return @"TRUE";
        } else {
             return @"FALSE";
        }
}

@end
TheDoty is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 332
12 members and 320 guests
akphyo, cgokey, EXOPTENDAELAX, flamingliquid, GHuebner, guusleijsten, ohmniac, Paul Slocum, PavelSea, SLIC, Sloshmonster, Sonuye857
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,653
Threads: 94,115
Posts: 402,888
Top Poster: BrianSlick (7,990)
Welcome to our newest member, ohmniac
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:29 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0