• 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 and don`t retain in accessor methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: retain and don`t retain in accessor methods


  • Subject: Re: retain and don`t retain in accessor methods
  • From: Kyle Sluder <email@hidden>
  • Date: Mon, 16 Nov 2009 10:29:35 -0800

On Mon, Nov 16, 2009 at 5:18 AM, Austin Ziegler <email@hidden> wrote:
> Is that true anymore, though? I've been looking at a lot of sample
> code lately, and it's very common practice to use "self.foo = ..." in
> initializers, even when they're declared nonatomic. I know you said
> you don't subscribe to it, but it seems to be an accepted practice
> these days.

On the contrary, it is becoming less of an accepted practice.  Perhaps
the reason you see code like that is because due to a previous
compiler bug it was impossible to access synthesized instance
variables by any means other than going through their accessors.  This
has now been fixed; you can use self->foo syntax to get at the
instance variable.

There are cases where you do, in fact, want to use accessors in your
initializer.  For example, say you subclass NSObjectController to make
some undo-manager-controller thingy (don't ask me what for, this is a
hypothetical).  You replace its designated initializer with one like
-initWithUndoManager:.  You might want to call super's -setContent:
rather than using the -initWithContent: initializer for whatever
reason.

> * have two different initializers with different names indicating the
> different ownership (e.g., initWithTarget, initWithObserved). You may
> have some code duplication here, but you could minimize some of that
> with a "- (void)initTimer" method that sets time and calls begin.

This is the direction I'd go in.

--Kyle Sluder
_______________________________________________

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: 
 >Fwd: retain and don`t retain in accessor methods (From: Ariel Feinerman <email@hidden>)
 >Re: retain and don`t retain in accessor methods (From: Kyle Sluder <email@hidden>)
 >Re: retain and don`t retain in accessor methods (From: Ariel Feinerman <email@hidden>)
 >Re: retain and don`t retain in accessor methods (From: Clark Cox <email@hidden>)
 >Re: retain and don`t retain in accessor methods (From: Austin Ziegler <email@hidden>)

  • Prev by Date: Re: CALayer Transitions
  • Next by Date: Re: CALayer Transitions
  • Previous by thread: Re: retain and don`t retain in accessor methods
  • Next by thread: Where are the interface builder components?
  • Index(es):
    • Date
    • Thread