本文介绍了如何为NSDictionary添加布尔值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好吧,对于整数,我会使用 NSNumber
。但是,我想,YES和NO不是对象。据我所知。我只能将对象添加到 NSDictionary
,对吧?
Well, for integers I would use NSNumber
. But YES and NO aren't objects, I guess. A.f.a.i.k. I can only add objects to an NSDictionary
, right?
我找不到布尔值的任何包装类。有没有?
I couldn't find any wrapper class for booleans. Is there any?
推荐答案
你使用NSNumber。
它有init ...和number ...方法,它们采用布尔值,就像整数一样。等等。
It has init... and number... methods that take booleans, just as it does integers and so on.
来自:
// Creates and returns an NSNumber object containing a
// given value, treating it as a BOOL.
+ (NSNumber *)numberWithBool:(BOOL)value
和:
// Returns an NSNumber object initialized to contain a
// given value, treated as a BOOL.
- (id)initWithBool:(BOOL)value
和:
// Returns the receiver’s value as a BOOL.
- (BOOL)boolValue
这篇关于如何为NSDictionary添加布尔值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!