如何将这些打印文本放入Textfield? [英] how can i put these print text into Textfield?

查看:38
本文介绍了如何将这些打印文本放入Textfield?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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})"
     }
    }

推荐答案

您正在 async {} 闭包内使用 $ 0 .此闭包不包含任何参数,这意味着使用 $ 0 参数快捷方式无效.

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

您显然正在尝试从 getPendingNotificationRequests 回调中引用 requests 数组.您无法使用 $ 0 的原因是,它是通过 DispatchQueue.main.async {...} 闭包(不带参数)进行筛选的:

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:

尝试一下:

    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 始终引用当前作用域.因此,要从嵌套闭包访问闭包参数,必须将该参数命名(上面代码中的 requests ).

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

这篇关于如何将这些打印文本放入Textfield?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆