我已将我的一个核心数据属性设置为布尔值。现在,我需要设置它,但XCode一直告诉我它可能不响应setUseGPS。
I have set up one of my core data attributes as a Boolean. Now, I need to set it, but XCode keeps telling me that it may not respond to setUseGPS.
[ride setUseGPS: useGPS.on];在核心数据中设置布尔值的方法是什么?我所有其他属性都以这种方式设置,并且它们工作得很好。那么,不确定为什么布尔值无法以这种方式设置?
What is the method for setting a boolean in core data? All my other attributes are set this way, and they work great. So, not sure why a boolean does not work to be set this way?
推荐答案核心数据没有布尔值类型(确实如此,但它是一个NSNumber)。
Core Data "does not have" a Boolean type (it does, but it is an NSNumber).
所以要设置useGPS = YES的等价物。
So to set the equivalent of useGPS = YES.
[entity setUseGPS:[NSNumber numberWithBool:YES]];反之亦然:
BOOL isGPSOn = [[entity useGPS] boolValue];更新: 正如SKG所指出的,有文字在Objetive-C中,您现在可以更简单的方式执行此操作:
Update: As pointed out by SKG, With literals in Objetive-C you can now do it in a simpler way:
[entity setUseGPS:@YES]; BOOL isGPSOn = entity.useGPS.boolValue;更多推荐
iPhone:将布尔值保存到Core Data中
发布评论