简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM