Re: Any way to get a warning if a non-boolean type is used in an if expression?
Re: Any way to get a warning if a non-boolean type is used in an if expression?
- Subject: Re: Any way to get a warning if a non-boolean type is used in an if expression?
- From: Andy Lee <email@hidden>
- Date: Fri, 18 Oct 2013 10:58:14 -0400
On Oct 16, 2013, at 9:00 PM, Rick Mann <email@hidden> wrote:
> Well, I found -Wbool-conversion, but it didn't seem to warn me when I did:
>
> if (self.active)
>
> where self.active is an NSNumber* property (the correct code in this case was 'self.active.boolValue').
This is one reason NSNumber* is a poor return type for a property with boolean semantics; it's much too easy to forget to call boolValue. Another reason is that self.foo.boolValue will return false if foo is nil, which may not be what you want. If you own the relevant code I would recommend changing its return type.
I can understand still wishing there were a warning, because people coming from Java may be used to its auto-boxing feature, which would return the right thing whether the property is a Boolean (object) or boolean (primitive). (Apologies if I'm misremembering Java.)
--Andy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden