1
我一直尝试使用MASShortcut并按照说明我已经使用cocoapods添加它。然后我把它添加到我的< PROJ> -Bridging-Header.h文件和import
编在我的主迅速文件,但我不断收到错误MASShortcut没有这样的模块
No such module 'MASShortcut'
这里是我的设置:
的AppDelegate .swift:
import Cocoa
import Carbon
import MASShortcut
var kShortCut: MASShortcut!
@IBOutlet weak var shortcutView: MASShortcutView!
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
override func awakeFromNib() {
... omitted ...
}
override func viewDidLoad() {
super.viewDidLoad()
shortcutView.shortcutValueChange = { (sender) in
let callback: (() -> Void)!
if self.shortcutView.shortcutValue.keyCodeStringForKeyEquivalent == "k" {
self.kShortCut = self.shortcutView.shortcutValue
callback = {
print("K shortcut handler")
}
} else {
callback = {
print("Default handler")
}
}
MASShortcutMonitor.sharedMonitor().registerShortcut(self.shortcutView.shortcutValue, withAction: callback)
和我Podfile:
target 'myapp' do
# Comment this line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
pod 'MASShortcut', '~> 2'
# Pods for myapp
target 'myappTests' do
inherit! :search_paths
# Pods for testing
end
end
最后凸出桥接-Header.h:
#import <Cocoa/Cocoa.h>
#import <MASShortcut/Shortcut.h>
谢谢你的帮助。我传递了'no such module'错误,但现在正在''shortcutView.shortcutValueChange = {(sender)in'行中发生'致命错误:意外地发现nil,同时展开可选值'。 – Sparkmasterflex
@Sparkmasterflex可能意味着你没有连接你的插座,因此它是零。 –