Designated Initializer
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