Skip to content

Instantly share code, notes, and snippets.

@cbowns cbowns/gist:6056535
Created Jul 22, 2013

Embed
What would you like to do?
A model object with a BOOL property backed by an NSNumber in the implementation
// An example of a model object with a boolean property
// that's backed by an NSNumber from a JSON response
@interface ModelObject : NSObject
@property (nonatomic, assign, getter = isEnabled) BOOL enabled;
@end
@interface ModelObject ()
@property (nonatomic, strong) NSNumber *enabledNumber;
@end
@implementation ModelObject
- (id)init;
{
self = [super init];
if (self) {
// assuming a decoded JSON object…
_enabledNumber = [json valueForKey:@"enabled"]; // returns an NSNumber instance
}
return self;
}
#pragma mark - Dynamic properties
- (BOOL)isEnabled;
{
return self.enabledNumber.boolValue;
}
- (void)setEnabled:(BOOL)enabled;
{
self.enabledNumber = [NSNumber numberWithBool:enabled];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.