NSWindowController
的子类(在 Apple 的文档中关于基于文档的应用程序中推荐这样做)。 在 ObjC 中,您将创建一个 NSWindowController
子类的实例,发送 initWithWindowNibName:
消息,然后按照实现方式来实现,调用超类方法。在 Swift 中,
init(windowNibName)
仅作为方便的初始化器提供,而 NSWindowController
的指定初始化器是 init(window)
,显然希望我传递窗口。我不能从我的子类调用
super.init(windowNibName)
,因为它不是指定的初始化器,所以我显然必须实现 convenience init(windowNibName)
,进而需要调用 self.init(window)
。但如果我只有我的 nib 文件,该如何访问该文件的窗口并将其发送到该初始化器呢?
NSWindowController
时覆盖windowNibName
。请查看此处的“Subclassing NSWindowController”部分。https://developer.apple.com/documentation/appkit/nswindowcontroller - macshome