• 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: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?


  • Subject: Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
  • From: Graham Cox <email@hidden>
  • Date: Thu, 21 May 2015 09:53:28 +1000

> On 21 May 2015, at 6:50 am, Michael David Crawford <email@hidden> wrote:
>
> In my own code I started with nothing but ivars, but changed some of
> them to properties while neglecting to remove the original ivar.  This
> leaves me somewhat in the same situation as you.


Nothing wrong with that, AS LONG as you remember to add the @synthesize foo = myOriginalIvar in your implementation. Problem is, it’s not a compile-time error if you forget. It might not even be a runtime error, but it’s very likely a bug anyway, because when you think you’re manipulating < myOriginalIvar >, in fact it’s manipulating a hidden _foo ivar. At its most benign, this is just a minor waste of space for the < myOriginalIvar > storage, but if code (and legacy code is quite likely to do this) is sometimes accessing the ivar directly, and sometimes through the property, you have a very, very definite and insidious bug.

Frankly, (and I have said this before more than once) the design of autosynthesizing properties, added as it was later to properties themselves, is a nasty way to shoot yourself in the foot and not even realise it. Caught me out numerous times.

You can enable the warning CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS (“Implicit Synthesized Properties” in build settings) to at least be told when you pulled the trigger.

—Graham



_______________________________________________

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


References: 
 >Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar? (From: Alex Zavatone <email@hidden>)
 >Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar? (From: Ken Thomases <email@hidden>)
 >Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar? (From: Ken Thomases <email@hidden>)
 >Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar? (From: Michael David Crawford <email@hidden>)

  • Prev by Date: Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
  • Next by Date: Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
  • Previous by thread: Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
  • Next by thread: Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
  • Index(es):
    • Date
    • Thread