Thanks Thanks - 1 year ago 89
Objective-C Question

How can I add a boolean value to a NSDictionary?

Well, for integers I would use

. But YES and NO aren't objects, I guess. A.f.a.i.k. I can only add objects to an
, right?

I couldn't find any wrapper class for booleans. Is there any?

Answer Source

You use NSNumber.

It has init... and number... methods that take booleans, just as it does integers and so on.

From the NSNumber class reference:

// 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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download