如何将 (BOOL *) 插入 NSMutableDictionary
我正在尝试将布尔数据库值保存到映射中,如下所示 -
[recentTags setValue:[NSNumber numberWithBool:[aMessage isSet]] forKey:[aMessage tagName]];
它给我一个错误,提示“整数转换不兼容的指针发送 BOOL * 又名签名字符 * 到 'BOOL' 又名签名字符”
我如何将 BOOL* 插入到字典?
I am trying to save a boolean database value into a map as follows -
[recentTags setValue:[NSNumber numberWithBool:[aMessage isSet]] forKey:[aMessage tagName]];
It gives me an error saying "Incompatible pointer to integer conversion sending BOOL * aka signed char* to 'BOOL' aka signed char"
How would I insert a BOOL* into the dictionary?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 BOOL 包装在 NSNumber 中:
要得到它:
您可以将其他非对象类型(例如指针或结构)包装在 NSValue。
编辑:假设你真的指的是 BOOL* (指针):
Wrap the BOOL in an NSNumber:
To get it out:
You can wrap other non-object types (such as a pointer or a struct) in an NSValue.
EDIT: Assuming you really mean a BOOL* (pointer):
您的
isSet
方法需要具有以下签名:- (BOOL)isSet;
假设是这种情况,那么使用 titandecoy 提到的 NSNumber 应该不会有任何问题。
你的最后一句话引起了我的兴趣,
BOOL *
。当然你的意思是BOOL
,如果你绝对需要一个布尔引用,那么我建议你将初始/实际的BOOL存储在一个NSNumber中,并将该对象的引用存储在你的任何地方d 需要它(即你的 NSMutableDictionary)。Your
isSet
method would need to have the following signature:- (BOOL)isSet;
Assuming that is the case, there shouldn't be any problem using NSNumber as mentioned by titaniumdecoy.
Your last sentence intrigues me,
BOOL *
. Surely you meanBOOL
, if you absolutely need a boolean reference, then I would suggest you store the initial/actual BOOL in a NSNumber and store the references that object wherever you'd need it (i.e. your NSMutableDictionary).