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?
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.
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.
Yes, you can assign an int value to a bool object. Both are integer types, and the value is implicitly converted.
An object representing a dynamic collection of key-value pairs, for use instead of a Dictionary variable in cases that require reference semantics.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With