无法使用 NSUserDefaults 保存 bool 变量
我正在使用 XCode4.2 并开发 iPhone 应用程序
我通常使用 NSUserdefaults
保存数据(主要是字符串...)
我通常编写以下两行来保存数据:
historyvar=[NSUserDefaults standardUserDefaults];
[historyvar setObject:boolVar forKey:@"bool"];
我正在尝试保存一个 BOOL变量,但当我这样做时,我得到一个红色错误:
Implicit converstion of'BOOL' (aka 'signed char') to 'id' is disallowed with ARC
并且我得到一个警告(黄色错误)
不兼容的整数到指针转换发送'BOOL'(又名'signed char')到'id'类型的参数
是否有相当于Bool 变量的 NSUserDefaults ? 谢谢
I am using XCode4.2 and developing and iPhone App
I ususally save data using NSUserdefaults
(mainly strings ... )
I usually write the following two lines to save the data :
historyvar=[NSUserDefaults standardUserDefaults];
[historyvar setObject:boolVar forKey:@"bool"];
I am trying to save a BOOL variable but I get a red error when I do that :
Implicit converstion of'BOOL' (aka 'signed char') to 'id' is disallowed with ARC
and I get a warning (yellow error)
incompatible integer to pointer conversion sending 'BOOL'(aka 'signed char') to parameters of type 'id'
is there anything equivalent to NSUserDefaults for Bool varibles ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NSUserDefaults 有一个 -setBool:forKey: 方法。
然后你将能够得到一个实际返回的BOOL值,如下所示:
这样你就不必弄乱NSNumbers。
There's a -setBool:forKey: method of NSUserDefaults.
and then you'll be able to get an actual BOOL value returned like this:
This way you don't have to mess with NSNumbers.