Cannot perform selector with function as param

186 views Asked by At

I have one small quest for you guys. I want perform selector which contain function as param. But always getting runtime error.

This method is from iAd framework. And this is what I m trying to do:

 let sel = Selector("requestAttributionDetailsWithBlock:")
 if obj.responds(to: sel) { 
    obj.perform(sel, with: funcAsVar)
 }

where funcAsVar is a function as variable. Help please, guys

runtime error is: libswiftCore.dylib-[_SwiftValue dealloc]:

1

There are 1 answers

0
Dave Weston On BEST ANSWER

You can add @convention(block) on the parameter you pass to the perform method. Like this:

let sel = Selector("requestAttributionDetailsWithBlock:")
 if obj.responds(to: sel) { 
    obj.perform(sel, with: @convention(block) funcAsVar)
 }