how can i put these print text into Textfield?

假如想象 提交于 2019-12-03 01:21:47

问题


UNUserNotificationCenter.current().getPendingNotificationRequests {

    DispatchQueue.main.async{//Contextual closure type '() -> Void' expects 0 arguments, but 1 was used in closure body
     let str:String = ""
     self.finalresulter.text = str
     self.finalresulter.text = "\($0.map{$0.content.title})"
     }
    }

回答1:


You are using $0 inside async { } closure. This closure expects no arguments, which means using $0 argument shortcut is invalid.

You are evidently attempting to refer to requests array from getPendingNotificationRequests callback. The reason you can't by using $0 is that it's screened by DispatchQueue.main.async{ ... } closure with no arguments:

Try this:

    UNUserNotificationCenter.current().getPendingNotificationRequests { requests in
        DispatchQueue.main.async{
            let str:String = ""
            self.finalresulter.text = str
            self.finalresulter.text = "\(requests.map{$0.content.title})"
        }
    }

The rule for $0 claims that $0 always refers to current scope. Thus, to access closure argument from nested closure, that argument must be named (requests in the above code).



来源:https://stackoverflow.com/questions/48238971/how-can-i-put-these-print-text-into-textfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!