Lets say I have the following setup:
....
UISwitch gpsSwitch;
// the below object has a gpsEnabled property of type boolean - default NO
NSManagedObject *typeObject;
....
How exactly do I go about properly calling:
self.gpsSwitch.on = [self.typeObject valueForKey:@"gpsEnabled"];
This always returns warning: passing argument 1 o开发者_运维百科f 'setOn:' makes integer from pointer without a cast. and does not work.
I've tried:
(BOOL)[self.typeObject valueForKey:@"gpsEnabled"];
(NSInteger)[self.typeObject valueForKey:@"gpsEnabled"];
and none of these casts seem to work? What's fix? :)
[self.typeObject valueForKey:@"gpsEnabled"]
returns and NSNumber object.
[[self.typeObject valueForKey:@"gpsEnabled"] boolValue]
returns a BOOL.
self.gpsSwitch.on
needs a BOOL.
Even though you setup boolean or int or whatever in your core data model, they are always retreived/set as NSNumbers. Somewhat confusing. I like to make accessors in my NSManagedObject subclasses that do the conversion for me.
精彩评论