我想将一些文本传递到文本域但是有些错误.... idk为什么print()是有效的

时间:2018-01-10 12:19:33

标签: swift ios11 swift4 xcode9

swift4 Xocode9

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

    print($0.map { $0.content.title},",",$0.map { $0.content.subtitle},","
        ,$0.map { $0.content.body},","
        ,$0.map { $0.trigger!})

}

请帮忙...如何解决..

2 个答案:

答案 0 :(得分:0)

试试这个:

notificatecontent.text = "\($0.map{$0.content.title})"

答案 1 :(得分:-1)

此问题似乎与您的other question相同。为了不复制我在那里给出的现有答案,我只提到第二部分,它看起来像:

UNUserNotificationCenter.current().getPendingNotificationRequests { requests in 

    // Textfield assignment here ...

    print(requests.map { $0.content.title},",",requests.map { $0.content.subtitle},","
        ,requests.map { $0.content.body},","
        ,requests.map { $0.trigger!})
}

但是,除非您明确要在一行上打印所有内容,否则应使用常规for循环(或至少forEach方法)更好地替换此印刷品:

// 1
for item in requests {
    print(item.content.title, item.content.subtitle, item.content.body)
}
// 2
requests.forEach {
    print($0.content.title, $0.content.subtitle, $0.content.body)
}