2016-07-29 13 views
1

私はMASShortcutを試してみました。そこにある指示に従って、私はcocoapodsを使って追加しました。MASShortcutそのようなモジュールがありません

AppDelegate:私はその後、私のメインの迅速なファイルでそれを編ファイルとimport-がheader.hを-Bridging私<がproj>にこれを追加しましたが、私はエラーに

No such module 'MASShortcut'

を得続けるここに私のセットアップです.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 

、最終的にprojのブリッジング-HEADER.H

#import <Cocoa/Cocoa.h> 
#import <MASShortcut/Shortcut.h> 

答えて

1

はここAppDelegateソートのようになるはずものです。 abs30のいずれかのimport MASShorcutに注意してください。

import Cocoa 

@NSApplicationMain 
class AppDelegate: NSObject, NSApplicationDelegate { 

    var kShortCut: MASShortcut! 
    @IBOutlet weak var window: NSWindow! 

    @IBOutlet weak var shortcutView: MASShortcutView! 

    override func awakeFromNib() { 

     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.shared().register(self.shortcutView.shortcutValue, withAction: callback) 
     } 
    } 
} 

ブリッジヘッダーは次のようになります。

#ifndef Testin_Bridging_Header_h 
#define Testin_Bridging_Header_h 

#import <MASShortcut/Shortcut.h> 

#endif /* Testin_Bridging_Header_h */ 

Shortcut.hは、他のすべてのヘッダファイルをインポートします。あなたは、アプリケーションのビルド設定でブリッジングヘッダーを設定していることを確認し

  • :TESTINは(当然のテストに)

    他のいくつかのヒントを私のアプリの名前でした。

  • 最初にフレームワークを構築しない場合は、MASShortcutスキームからビルドを試してください。
  • AppDelegateにライフサイクルイベントがないため、ライフサイクルメソッド(つまりviewDidLoad)を使用するには、NSViewControllerまたはNSWindowControllerのいずれかのサブクラスを使用する必要があります。
+0

ありがとうございました。 'no such module'エラーを受け取りましたが、' shortcutView.shortcutValueChange = {(sender)in'行に '致命的なエラー:予期せぬことにオプション値をアンラッピングしています。 – Sparkmasterflex

+0

@ Sparkmasterflexおそらく、あなたのコンセントに接続していないことを意味します。したがって、それはゼロです。 –

関連する問題