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

Designated Initializer


  • Subject: Designated Initializer
  • From: Richard Somers <email@hidden>
  • Date: Sat, 30 Oct 2010 12:12:06 -0600

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


  • Follow-Ups:
    • Re: Designated Initializer
      • From: Dave Carrigan <email@hidden>
  • Prev by Date: Re: Adding and removing menu items causes memory usage to grow
  • Next by Date: Re: Designated Initializer
  • Previous by thread: Re: Get wrong tag value from NSPopupButtonCell
  • Next by thread: Re: Designated Initializer
  • Index(es):
    • Date
    • Thread