swiftruntimeselectoriad

Cannot perform selector with function as param


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]:


Solution

  • 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)
     }