how can i put these print text into Textfield?

后端 未结 1 1540
孤街浪徒
孤街浪徒 2021-01-29 16:04
UNUserNotificationCenter.current().getPendingNotificationRequests {

    DispatchQueue.main.async{//Contextual closure type \'() -> Void\' expects 0 arguments, but 1          


        
相关标签:
1条回答
  • 2021-01-29 16:12

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

    0 讨论(0)
提交回复
热议问题