插入 BOOL 的 Objective-C 字典

Objective-C dictionary inserting a BOOL(插入 BOOL 的 Objective-C 字典)
本文介绍了插入 BOOL 的 Objective-C 字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我有点困惑.这可能只是一件小事.

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:

传递 set 的参数 1... 使指针从整数而不进行强制转换"...

"Passing argument 1 of set... makes pointer from integer without a cast"...

我到底如何在字典中插入一个布尔值?

How on earth do I insert a bool into a dictionary?

推荐答案

NSDictionary 中的值必须是对象.要解决此问题,请将布尔值包装在 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"];

这篇关于插入 BOOL 的 Objective-C 字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to stop UIBarButtonItem text from truncating?(如何阻止UIBarButtonItem文本被截断?)
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type(异常:不应为错误类型创建SimpleTypeImpl)
Android IllegalArgumentException: The tag for fragment_XXX is invalid. Received: layout-sw600dp/fragment_XXX_0(Android IlLegalArgumentException:Fragment_XXX的标签无效。收到:Layout-sw600dp/Fragment_XXX_0)
NSURLSessionTaskPriority seems to be ignored?(NSURLSessionTaskPriority似乎被忽略了?)
How to make dataWithEPSInsideRect vector rather than bitmap in vector format?(如何用EPSInside Rect将dataWithEPSInside Rect变成矢量而不是位图的矢量格式?)
HTTPS request using volley(使用 volley 的 HTTPS 请求)