Take the 2-minute tour ×

I am trying to save a boolean database value into a map as follows -

[recentTags setValue:[NSNumber numberWithBool:[aMessage isSet]] forKey:[aMessage tagName]];

It gives me an error saying "Incompatible pointer to integer conversion sending BOOL * aka signed char* to 'BOOL' aka signed char"

How would I insert a BOOL* into the dictionary?

share|improve this question
Why does -isSet return BOOL * instead of BOOL? –  Bavarious Nov 21 '11 at 8:15

2 Answers 2

up vote 28 down vote accepted

Wrap the BOOL in an NSNumber:

NSNumber *boolNumber = [NSNumber numberWithBool:YES];

To get it out:

BOOL b = [boolNumber boolValue];

You can wrap other non-object types (such as a pointer or a struct) in an NSValue.

EDIT: Assuming you really mean a BOOL* (pointer):

NSValue *boolValue = [NSValue value:pointerToBool withObjCType:@encode(BOOL*)];
BOOL *b = [boolValue pointerValue];
share|improve this answer
As you can see in my question I am already doing that but it's not working for me. That is when I get the error that I have mentioned. –  Suchi Nov 11 '11 at 1:09
Are you sure [aMessage isSet] is returning a BOOL and not a BOOL*? If it returns the latter, you need to use [NSNumber numberWithBool:*[aMessage isSet]] (although you should first check that it is not NULL). –  titaniumdecoy Nov 11 '11 at 1:17
Starting with Clang v3.1, we can use literals: NSNumber *yesNumber = @YES; and NSNumber *noNumber = @NO;, equivalent to [NSNumber numberWithBool:YES] etc –  coco May 10 '13 at 23:00

Your isSet method would need to have the following signature: - (BOOL)isSet;

Assuming that is the case, there shouldn't be any problem using NSNumber as mentioned by titaniumdecoy.

Your last sentence intrigues me, BOOL *. Surely you mean BOOL, if you absolutely need a boolean reference, then I would suggest you store the initial/actual BOOL in a NSNumber and store the references that object wherever you'd need it (i.e. your NSMutableDictionary).

share|improve this answer

Your Answer


