I found some code similar to the following:
BOOL hasValue_:1;
- (BOOL) hasValue {
return !!hasValue_;
}
- (void) setHasValue:(BOOL) value {
hasValue_ = !!value;
}
I'm wondering why the double exclamation points are necessary? Are we not already passing BOOL to the method and returning BOOL? Is BOOL really a typedef for an int?
Thanks!
EDIT
Thanks for all of the responses thus far. I understand that using !! with other data types effectively performs some typecasting to a boolean result. However, in the example above, I'm strictly working with BOOL already.
EDIT
If I'm working with a BOOL already, why is it necessary to normalize it to a 0 for false and 1 for true? Doesn't a BOOL guarantee that it is false for 0 and true for everything else?