• 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: Designated Initializer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Designated Initializer


  • Subject: Re: Designated Initializer
  • From: Dave Carrigan <email@hidden>
  • Date: Sat, 30 Oct 2010 12:12:16 -0700

All initialized objects have at some point called super; they aren't fully initialized otherwise. In the implementation, the non-designated initializers typically chain to the designated initializer, which in turn chains to super's (usually designated) initializer. So just because a designated initializer didn't call super's designated initializer, it doesn't mean that super's designated initialer was not invoked; it was.

On Oct 30, 2010, at 11:12 AM, Richard Somers wrote:

> A class can have many initializers. According to the documentation for NSObject, by convention the initializer that includes a message to super (usually the one with the most arguments) is the designated initializer for the class. This initializer should begin by sending a message to super to invoke the designated initializer of the superclass.
>
> On page 192 of Cocoa Programming for Mac OS X, Third Edition, by Hillegass there is an initializer for a NSWindowController subclass that looks something like this (altered slightly).
>
> - (id)init // NSWindowController subclass designated initializer
> {
>     self = [super initWithWindowNibName:@"MyNibFile"];
>     if (self) {
>         // Initialization code.
>     }
>     return self;
> }
>
> This is the only initializer this subclass implements and by convention it is the designated initializer because it calls super.
>
> But note that the initializer does not call the designated initializer of the superclass which would be 'initWithWindow:'. It calls 'initWithWindowNibName:' instead, which is not the designated initializer of the superclass.
>
> So my question is, what are the implications if the designated initializer does not call the designated initializer of the superclass but calls one of the other initializers instead?
>
> --Richard Somers
>
> _______________________________________________
>
> 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

_______________________________________________

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

  • Follow-Ups:
    • Re: Designated Initializer
      • From: Richard Somers <email@hidden>
    • Re: Designated Initializer
      • From: mmalc Crawford <email@hidden>
    • Re: Designated Initializer
      • From: Quincey Morris <email@hidden>
References: 
 >Designated Initializer (From: Richard Somers <email@hidden>)

  • Prev by Date: Designated Initializer
  • Next by Date: Re: Designated Initializer
  • Previous by thread: Designated Initializer
  • Next by thread: Re: Designated Initializer
  • Index(es):
    • Date
    • Thread