• 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: Retain/Release and Properties clarification
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Retain/Release and Properties clarification


  • Subject: Re: Retain/Release and Properties clarification
  • From: Andy Lee <email@hidden>
  • Date: Fri, 07 Oct 2011 19:46:17 -0400

On Oct 3, 2011, at 2:23 PM, Charles Srstka wrote:
> 2. KVO’s “access instance variables directly” (mis)feature recognizes the underscore prefix. I like to give it a prefix that KVO doesn’t know about so that I can be sure never to end up accidentally accessing the ivars of another object without going through the proper accessors.

Ooh, hadn't thought of that.

Maybe now's the time to start using spiffy compiler features like synthesized ivars, and to stop declaring ivars at all.

On Oct 7, 2011, at 1:21 PM, Glenn L. Austin wrote:
> The proper way (today) to mark an ivar as private is to use @private.  Go ahead and use a leading underscore, but don't be surprised if sometime in the future you are debugging a strange compile-time error. (I've been 'bit' by this a few times in my development).

The reason I use an underscore for ivars has nothing to do with it marking it private (which I do anyway with @private). It's to be able to spot them more easily in my implementation code. If I get a compile-time error I can always rename the ivar.

More dangerous is runtime errors due to a pseudo-private *method* name that you didn't realize overrides a method in a superclass. I confess I use the underscore prefix for "private" methods, but my private methods tend to be pretty non-generic.

--Andy

_______________________________________________

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: 
 >Retain/Release and Properties clarification (From: John Tsombakos <email@hidden>)
 >Re: Retain/Release and Properties clarification (From: John Tsombakos <email@hidden>)
 >Re: Retain/Release and Properties clarification (From: Charles Srstka <email@hidden>)
 >Re: Retain/Release and Properties clarification (From: Sean McBride <email@hidden>)
 >Re: Retain/Release and Properties clarification (From: "Glenn L. Austin" <email@hidden>)

  • Prev by Date: [Q] how to tell NSNotificationCenter to send posted noti?
  • Next by Date: AuthorizationServices - what is wrong here?
  • Previous by thread: Re: Retain/Release and Properties clarification
  • Next by thread: Re: Retain/Release and Properties clarification
  • Index(es):
    • Date
    • Thread