• 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: Implied use of Properties
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Implied use of Properties


  • Subject: Re: Implied use of Properties
  • From: Quincey Morris <email@hidden>
  • Date: Fri, 2 Apr 2010 14:18:17 -0700

On Apr 2, 2010, at 13:48, Dave wrote:

> Is this normal? Looking at the code it seems hard to see what is going on, Surely it would be better practice to have an init method that does this? e.g.
>
> self.mClassY = [[alloc] initWithData: initWithData:someData]

It's perfectly normal for a class to defer creating the contents of an instance variable until it's needed. (There's no way an client of the class can tell the difference.) However, there's not much point in doing so *unless* creating it is so expensive in terms of memory or performance that there's an actual benefit in doing the deferring.

Incidentally, your suggested line of code above doesn't follow current best practices (aside from the typo in the 'alloc' invocation). It would be placed in ClassX's -init method, and the current fashion (for good technical reasons) in an -init method is *typically* to set the instance variable directly:

	mClassY = [[ClassY alloc] initWithData: initWithData:someData];

instead of using the setter as you proposed. Also, your version would produce a memory leak.


_______________________________________________

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: 
 >Implied use of Properties (From: Dave <email@hidden>)

  • Prev by Date: Re: Creating WebView in code
  • Next by Date: Re: Implied use of Properties
  • Previous by thread: Implied use of Properties
  • Next by thread: Re: Implied use of Properties
  • Index(es):
    • Date
    • Thread