Unable to use Objective-C library in Swift project -


i've tried import objective-c library named ddhotkey in swift project , doesn't work in cases.

here steps i've done:

  • download "ddhotkey" repository
  • right-click on project -> "add files %project_name%" -> select "ddhotkey-master" folder "copy items if needed" checkbox , "create folder references" radiobutton enabled
  • according apple documentation, prompt bridging header should appear then, didn'tt-- files copied project's directory
  • i've tried add bridging header project manually (file -> new -> source -> header file) name "bridge.h", set in project's settings (build settings -> swift compiler - code generation -> objective-c bridging header -> "bridge.h") , place following code file:

.

#ifndef project_name_bridge_h #define project_name_bridge_h  #import "ddhotkey-master/ddhotkeycenter.h"  #endif 

now compiles following code:

var hotkeycenter = ddhotkeycenter.sharedhotkeycenter() 

but when tried call method of object i've got error:

hotkeycenter.registerhotkeywithkeycode(34, modifierflags: 0, task: (nsevent) {     println("str") }) 

missing argument parameter 'action' in call

though there 2 methods , use different one:

- (ddhotkey *)registerhotkeywithkeycode:(unsigned short)keycode modifierflags:(nsuinteger)flags target:(id)target action:(sel)action object:(id)object;  - (ddhotkey *)registerhotkeywithkeycode:(unsigned short)keycode modifierflags:(nsuinteger)flags task:(ddhotkeytask)task; 

why? doing wrong? how can fix it?

thanks in advance.

your closure syntax incorrect. think mean following:

hotkeycenter.registerhotkeywithkeycode(34, modifierflags: 0, task: { _ in     println("str") }) 

the _ in may unnecessary if type inference can figure things out, suspect need it. leading (nsevent) not proper swift syntax, however.


Comments

Popular posts from this blog

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -

How to run C# code using mono without Xamarin in Android? -