I'm creating my own subclass of NSApplication, and am running into a roadblock. Here is my implementation of the run()
method.
override func run() {
finishLaunching()
repeat {
let event = nextEventMatchingMask(0xfffffffffffffff, untilDate: NSDate.distantPast(), inMode: NSDefaultRunLoopMode, dequeue: true)
if event != nil { sendEvent(event!) }
updateWindows()
} while true
}
In my main.swift
I have this:
let myApp: MyApplication = MyApplication.sharedApplication() as! MyApplication
let window = NSWindow(contentRect: NSMakeRect(0, 0, 100, 100), styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask , backing: .Buffered, defer: false)
window.makeKeyAndOrderFront(nil)
myApp.run()
The reason why I have 0xfffffffffffffff
instead of Int(NSEventMask.AnyEventMask.rawValue)
is because the latter overflows when converted from UInt64
to Int
.
The problem is, when I click on the red close button, the window does not close, and when I select "Quit" from the dock icon menu, it does not quit. Why does this happen?
EDIT: The same problem is discussed in this answer.
EDIT 2: I've created an objective-c version of this code, and everything works fine. I suspect the problem is that I can't use NSAnyEventMask in Swift.