• 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: What classes have -init?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What classes have -init?


  • Subject: Re: What classes have -init?
  • From: Greg Parker <email@hidden>
  • Date: Thu, 11 Feb 2010 11:55:25 -0800

On Feb 11, 2010, at 9:03 AM, Gordon Apple wrote:
> It's unfortunate that all initializers don't at least call "init"
> internally.  That would make subclassing easier if all one needs is to set a
> few ivars.  In the earlier days of MacApp (Pascal and first C++ versions)
> there was a basic initializer, similar to "init", called by all classes,
> just for that purpose.  Of course, Objective C at least sets them all to
> zero, reducing the need -- but it still would have been useful, sometimes
> eliminating the need to override multiple initializers.

The designated initializer pattern solves the problem in a similar way. Every initializer in a class is expected to call through that class's designated initializer eventually. When you subclass a class, you can override just the designated initializer to do your work and then call super's designated initializer. All of the superclass's other initializers will funnel through your code without any additional overrides.


--
Greg Parker     email@hidden     Runtime Wrangler

_______________________________________________

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: 
 >Re: What classes have -init? (From: Gordon Apple <email@hidden>)

  • Prev by Date: iPhone: UIWebView not displaying until scrolled?
  • Next by Date: Re: What classes have -init?
  • Previous by thread: Re: What classes have -init?
  • Next by thread: Re: What classes have -init?
  • Index(es):
    • Date
    • Thread