开发者

How to correctly set a UISwitch ON state using a NSManagedObject boolean attribute type?

开发者 https://www.devze.com 2023-02-17 18:39 出处:网络
Lets say I have the following setup: .... UISwitch gpsSwitch; // the below object has a gpsEnabled property of type boolean - default NO

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消