iPhone:将布尔值保存到Core Data中

编程入门 行业动态 更新时间:2024-10-20 08:00:24
本文介绍了iPhone:将布尔值保存到Core Data中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已将我的一个核心数据属性设置为布尔值。现在,我需要设置它,但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中

本文发布于:2023-11-17 07:08:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609251.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布尔值   iPhone   Data   Core

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!