2017-03-06 45 views
0

我对你们有一个小小的追求。 我想执行包含函数作为参数的选择器。但总是得到运行时错误。无法使用功能作为参数执行选择器

此方法来自iAd框架。这就是我想要做的:

​​

其中funcAsVar是一个函数作为变量。 帮助请家伙

运行时错误是:libswiftCore.dylib-[_SwiftValue dealloc]:

+0

什么是运行时错误? – NobodyNada

+0

我不认为Swift函数会自动桥接到Objective C块。你有没有试过一个调用函数的Swift块? –

+1

实际上,您可能可以在传递给'perform'方法的参数上使用'@convention(block)'。 –

回答

1

你可以在你传递给perform方法参数添加@convention(block)。像这样:

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