I am attempting to set an outlet for the main window of my app in my App Delegate, then connect it within Interface Builder. I create the outlet within my App Delegate easily:
@IBOutlet weak var mainWindow: NSWindow!
However there's no way, within interface builder, for me to connect a referencing outlet to the App Delegate. Instead, I can only connect it to the Window Controller, which I hope this picture shows:
The first object is the Window Controller and the second object is the First Responder, however the App Delegate object is missing. The menubar has the App Delegate object:
And I can connect anything from the menubar to any outlets in the App Delegate.
I figure I can access the window object by using:
NSApp.windows[0]
But that seems prone to error, especially if I have more than one window.
I dont know if this is correct way of doing, but this will solve your problem.
Decalre a NSWindow property in AppDelegate
weak var window: NSWindow!
and set the property in something like windowWillLoad of the NSWindowController
(NSApplication.sharedApplication().delegate as! AppDelegate).window = self.window
You will have to subclass NSWindowController to define windowWillLoad
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With