swiftmacosxcode9.2

How do I create an IBOutlet for NSWindow Xcode macOS


I am trying to create an IBOutlet for NSWindow in AppDelegate.swift, I am able to create IBOutlets for buttons by control + dragging from storyboard to swift file, but I am not able to do this for NSWindow. How do I do this? Xcode 9.2 Swift 4.0

Thanks


Solution

  • Create a window property:

    weak var window: NSWindow?
    

    Main window reference:

     func applicationDidFinishLaunching(_ aNotification: Notification) {
            window = NSApplication.shared.windows.first
        }