Re: BOOL attribute types.
Re: BOOL attribute types.
- Subject: Re: BOOL attribute types.
- From: Alex Zavatone <email@hidden>
- Date: Wed, 18 Feb 2015 13:02:07 -0500
Thanks Jens. One issue I found in trying to do this is that a BOOL with a NO and a BOOL with a nil value will both return NO when doing [self valueForKey:propertyName].
In creating an autoDescription method for objects, it's important to know if our BOOLs are NO or nil.
Any ideas on how to get the value so that the correct value of nil can be returned in nil cases?
Can't wait to see what fun happens when checking other types for nil results.
Cheers,
Alex
Sent from my iPad. Please pardon typos.
On Feb 16, 2015, at 4:49 PM, Jens Alfke <email@hidden> wrote:
>
>> On Feb 16, 2015, at 1:27 PM, Akis Kesoglou <email@hidden> wrote:
>>
>> objc.h typedefs BOOL as char/bool, as David says, so I don’t think you can infer that a property is BOOL by introspecting the property — you’ll always see char or bool.
>
> I’ll chime in too — there’s no way to tell the difference. If you need to detect boolean properties and treat them differently from ‘char’, you’ll have to enforce that your classes only use ‘bool’ properties, not ‘BOOL’.
>
> And a bit of advice if you go this route: If you start using ‘bool’ in your code, make sure you enable the “Implicit ‘bool’ Conversions” warning in Xcode. Otherwise the default semantics of ‘bool’ in C99 allow for some really nasty bugs, like
> bool x;
> …
> x = [NSMutableArray array]; // compiles with no warning! :-o
> C99 lets you assign a value of almost any type (except for a struct/union) to a bool variable. The warning was added later because this turns out to have bad side effects. A few years ago I had a serious and very hard to identify bug in my code that stemmed from this sort of mistake. After a few hours I stared at the assignment statement, then looked up the declaration of the variable, and did a double-take when I realized it was a bool and not an object reference…
>
> —Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden