Objective-C的字典插入BOOL [英] Objective-C dictionary inserting a BOOL
本文介绍了Objective-C的字典插入BOOL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
OK,我有点困惑。
这可能只是一个平凡。
OK, I'm a little confused. It's probably just a triviality.
我有一个功能,它看起来是这样的:
I've got a function which looks something like this:
- (void)getNumbersForNews:(BOOL)news andMails:(BOOL)mails {
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[parameters setValue:news forKey:@"getNews"];
[parameters setValue:mails forKey:@"getMails"];...}
不要紧,我是使用的setValue:forKey:
或的setObject:ForKey:
,我总是得到一个警告:
It doesn't matter whether I use setValue:forKey:
or setObject:ForKey:
, I'm always getting a warning:
设置传递的参数1 ...使指针从整数,未作类型转换...
"Passing argument 1 of set... makes pointer from integer without a cast"...
如何在地球上我插入一个布尔到字典?
How on earth do I insert a bool into a dictionary?
推荐答案
值。为了解决这个问题,敷在布尔的NSNumber
对象:
Values in an NSDictionary
must be objects. To solve this problem, wrap the booleans in NSNumber
objects:
[parameters setValue:[NSNumber numberWithBool:news] forKey:@"news"];
[parameters setValue:[NSNumber numberWithBool:mails] forKey:@"mails"];
这篇关于Objective-C的字典插入BOOL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文