Starting with a blank OS X application project, I add the following code to applicationDidFinishLaunching
.
func applicationDidFinishLaunching(aNotification: NSNotification) {
let app = NSApplication.sharedApplication()
guard let window = app.keyWindow else {
fatalError("No keyWindow\n")
}
print(window)
}
At launch I hit the error case because my local window
variable is nil. Yet when I show the contents of the app variable, I see a valid value for _keyWindow
. Also notice that the blank GUI Window is being displayed on the screen next to the stack dump.
Why does the keyWindow: NSWindow?
property return nil in this case?
Thanks