I'm looking over the diffs submitted to a project by another developer, and they have a lot of code that does !!<some BOOL value>
. In fact, this seems to be their standard pattern for implementing boolean getters and setters. They've implemented their code like:
- (BOOL) hasId {
return !!hasId_;
}
- (void) setHasId:(BOOL) value {
hasId_ = !!value;
}
I've never seen this pattern before, and am wondering if there is any benefit in using it. Is the double-negation doing anything useful?
The double boolean operator just makes sure that the value returned is either a 1 or a 0. That's all : )
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