Reputation: 24481
In objective-c, if I wanted to reverse the value of a BOOL
, would this work, or would it set the value of the BOOL
to NO
?
BOOL ab = YES;
ab = !ab; // would this reverse the BOOL, ab, and set it to NO?
if (ab == NO) {
ab = !ab; // would this reverse the BOOL again and set it to YES?
}
Upvotes: 4
Views: 5450
Reputation: 1
These are correct!
This is not correct!
FreeAsInBeer: "YES is equal to anything else (except NULL)." - NOT TRUE
YES equals to nothing but the signed char 1, so YES == 32626 for instance returns false!!
Upvotes: 0
Reputation: 12979
BOOL
s work exactly as you have described. Not that NO
is 0
and YES
is equal to anything else (except NULL
).
Examples:
Upvotes: 1
Reputation: 63472
Yes, that will work. BOOL
is just an integer. YES
is 1
and NO
is 0
. !1 == 0
and !0 == 1
.
Upvotes: 8