When I’m trying to do this to get the BOOL from a dictionary, I get:
BOOL isTrue = [someDict objectForKey: @"isTrue"];
I get:
Initialization makes integer from pointer without a cast
I set the dictionary by doing this:
self.someDict = [[NSMutableDictionary alloc]
initWithObjectsAndKeys:
self.isTrue, @"isTrue",
nil];
Any ideas?
Use:
The only way to store a
BOOLin anNSDictionaryis to box it in anNSNumberobject. ABOOLis primitive, and a dictionary only holds objects.Similarly, to store a
BOOLin a dictionary, use:EDIT: (in response to a comment)
There are two ways of representing this as an
@property. One is to declare the ivar as aBOOL, and the other is to declare it as anNSNumber.For the first case, the ivar is:
BOOL isTrue;, and the property is@property BOOL isTrue;(I’m ignoring naming conventions, obviously).For the
NSNumber, the ivar is:NSNumber * isTrue;and the property is@property (nonatomic, retain) NSNumber * isTrue;. If you go with this route, you might want to provide a second setter method (setIsTrueBoolor something) that allows you to just pass inYESorNO, and then you do the boxing yourself. Otherwise anyone who calls this would have to do the boxing themselves.I’d personally most likely go with option #1, but it really depends on what the class’s purpose was.