本文介绍了Swift中的NSApplication子类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了NSApplication子类:
I created NSApplication subclass:
class MyApplication: NSApplication {
override func sendEvent(theEvent: NSEvent) {
if theEvent.type == NSEventType.KeyUp && (theEvent.modifierFlags & .CommandKeyMask).rawValue != 0 {
self.keyWindow?.sendEvent(theEvent)
} else {
super.sendEvent(theEvent)
}
}
}
此后,我将Info.plist中的"Principal class"更改为MyApplication,最后在Main.storyboard的Application Scene中,我也将Application更改为MyApplication.
After that, I changed "Principal class" in Info.plist to MyApplication and at the end in the Application Scene in Main.storyboard, I changed Application to MyApplication, too.
运行应用程序时,我收到以下消息:
When I run application I get following message:
有人可以帮我吗?
推荐答案
尝试:
@objc(MyApplication)
class MyApplication: NSApplication {
或者,您必须像这样设置Info.plist.
OR, you have to set Info.plist like this.
<key>NSPrincipalClass</key>
<string>YourAppName.MyApplication</string>
^^^^^^^^^^^^
目前没有确切的文档,但是:
There is no exact document about this, but this description is corresponding:
和:
这篇关于Swift中的NSApplication子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!