簡體   English   中英

無法執行具有參數功能的選擇器

[英]Cannot perform selector with function as param

我對你們有一個小任務。 我想執行包含功能作為參數的選擇器。 但是總是會出現運行時錯誤。

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

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

其中funcAsVar是一個變量函數。 伙計們,請幫忙

運行時錯誤為: libswiftCore.dylib-[_SwiftValue dealloc]:

您可以在傳遞給perform方法的參數上添加@convention(block) 像這樣:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM