您正在使用
$0
在…内
async { }
关闭。此闭包不需要参数,这意味着使用
$0
参数快捷方式无效。
你显然是想提到
requests
阵列自
getPendingNotificationRequests
回调。您无法使用的原因
$0
是由
DispatchQueue.main.async{ ... }
无参数闭包:
尝试以下操作:
UNUserNotificationCenter.current().getPendingNotificationRequests { requests in
DispatchQueue.main.async{
let str:String = ""
self.finalresulter.text = str
self.finalresulter.text = "\(requests.map{$0.content.title})"
}
}
的规则
$0
声称
$0
始终引用当前范围
. 因此,要从嵌套闭包访问闭包参数,必须命名该参数(
请求
在上述代码中)。