Re: Designated initializers


Quincey Morris
 

On Oct 4, 2018, at 14:48 , James Walker <list2@...> wrote:

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.

Yes, this is kinda broken for NSWindowController subclasses because “init(windowNibName:owner:)” kinda oughta be a designated initializer but isn’t.

What you should be able to do is define “convenience init(parameter:)” but no other inits. That will let all superclass inits (both designated and convenience) get inherited, and your “init(parameter:)” is then allowed to call “across” to another convenience init — “init(windowNibName:owner:)” in this case. So, this compiles:

    convenience init(parameter: String) {
        self.init(windowNibName: ) // <— ’self’ not ’super’ because it’s been inherited
    }

    


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