I am trying to start a new document based Cocoa project in Swift and want to create a subclass of NSWindowController
(as recommended in Apple's guides on document based apps). In ObjC you would make an instance of an NSWindowController
subclass sending the initWithWindowNibName:
message, which was implemented accordingly, calling the superclasses method.
In Swift init(windowNibName)
is only available as an convenience initializer, the designated initializer of NSWindowController
is init(window)
which obviously wants me to pass in a window.
I cannot call super.init(windowNibName)
from my subclass, because it is not the designated initializer, so I obviously have to implement convenience init(windowNibName)
, which in turn needs to call self.init(window)
. But if all I have is my nib file, how do I access the nib file's window to send to that initializer?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…