I am trying to make sub class of NSApplication with this code:
class MySubNSApplication: NSApplication {
static var internalShared: MySubNSApplication = MySubNSApplication()
static override var shared: MySubNSApplication {
get {
return internalShared
}
set(newValue) {
internalShared = newValue
}
}
}
And it seems the codes are ok, but I have issue to make use of it, the normal coding for super class would be:
let nsApplication: NSApplication = NSApplication.shared
And if want make use of MySubNSApplication, that would be this below codes in a main file:
import Cocoa
let myNSApplication: MySubNSApplication = MySubNSApplication.shared
let appDelegate: AppDelegate = AppDelegate()
myNSApplication.delegate = appDelegate
myNSApplication.run()
Which the error happens on line of myNSApplication.run()
:
Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
How can I solve this error?
update:
import Cocoa
let myNSApplication = NSApplication.shared as? MySubNSApplication
let appDelegate: AppDelegate = AppDelegate()
myNSApplication?.delegate = appDelegate
myNSApplication?.run()