Designated initializers


James Walker
 

I was looking at the Xcode operation Edit > Convert > To Modern Objective-C Syntax, and what it does with NS_DESIGNATED_INITIALIZER markup.  I know, I'm late to the party.

I often have a subclass of NSWindowController with one initializer, say

(instancetype) initWithParameter: (NSString*) name;

that is implemented using -[NSWindowController initWithWindowNibName:].  But the rules say that a designated initializer must call a superclass designated initializer, while a convenience initializer must call some other initializer of my own class.  Since initWithWindowNibName: is not a designated initializer of NSWindowController, it seems that my initializer can’t be either kind of initializer.  Do I need to override NSWindowController’s designated initializers, plus override initWithWindowNibName:, and then have my own initializer call my own initWithWindowNibName:?  Seems like a lot of trouble for little benefit.  Nobody should ever be calling any other initializer of my subclass.

Join {cocoa@apple-dev.groups.io to automatically receive all group messages.