Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to insert a (BOOL *) into NSMutableDictionary

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?

like image 1000
Suchi Avatar asked Nov 11 '11 00:11

Suchi


People also ask

How do you assign a Boolean?

Boolean variables are variables that can have only two possible values: true, and false. To declare a Boolean variable, we use the keyword bool. To initialize or assign a true or false value to a Boolean variable, we use the keywords true and false.

What is bool in C sharp?

The bool type keyword is an alias for the . NET System. Boolean structure type that represents a Boolean value, which can be either true or false . To perform logical operations with values of the bool type, use Boolean logical operators. The bool type is the result type of comparison and equality operators.

Can you assign an int to a bool?

Yes, you can assign an int value to a bool object. Both are integer types, and the value is implicitly converted.

What is NSMutableDictionary?

An object representing a dynamic collection of key-value pairs, for use instead of a Dictionary variable in cases that require reference semantics.


1 Answers

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];
like image 91
titaniumdecoy Avatar answered Oct 03 '22 18:10

titaniumdecoy