• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: BOOL attribute types.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: BOOL attribute types.


  • Subject: Re: BOOL attribute types.
  • From: Jens Alfke <email@hidden>
  • Date: Mon, 16 Feb 2015 13:49:02 -0800

> 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


  • Follow-Ups:
    • Re: BOOL attribute types.
      • From: Alex Zavatone <email@hidden>
References: 
 >BOOL attribute types. (From: Alex Zavatone <email@hidden>)
 >Re: BOOL attribute types. (From: David Duncan <email@hidden>)
 >Re: BOOL attribute types. (From: Alex Zavatone <email@hidden>)
 >Re: BOOL attribute types. (From: Akis Kesoglou <email@hidden>)

  • Prev by Date: Re: NSWindowControllers and NSWindow
  • Next by Date: Re: NSWindowControllers and NSWindow
  • Previous by thread: Re: BOOL attribute types.
  • Next by thread: Re: BOOL attribute types.
  • Index(es):
    • Date
    • Thread