johnbakers
johnbakers

Reputation: 24760

How to cast a variable in Key Value Coding

 [self setValue:flag forKey:variableName];

"flag" is a method's local BOOL; the keypath is also a BOOL member variable. But I get the Xcode warning `Incompatible integer to pointer conversion."

I also tried:

 [self setValue:(BOOL)flag forKey:variableName];

How do I get rid of this warning?

Upvotes: 0

Views: 106

Answers (1)

Rob Napier
Rob Napier

Reputation: 299355

KVC automatically boxes and unboxes non-objects. For the above case, you would use:

[self setValue:[NSNumber numberWithBool:flag] forKey:variableName];

See Scalar and Structure Support in the Key-Value Coding Programming Guide.

Upvotes: 1

Related Questions