gpt4 book ai didi

swift - 在任务完成时设置启动器 View Controller 的变量

转载 作者:行者123 更新时间:2023-11-28 15:16:15 25 4
gpt4 key购买 nike

我正在执行一个异步 HTTP POST 任务,在完成时我需要将结果发送回启动器viewcontroller。我已经连接到完成处理程序并且一切都按预期工作。但是由于这个错误,我无法正确声明返回变量

在闭包中隐式使用“self”;使用“ self ”。使捕获语义明确

                dourltask() { isValid in 
// do something with the returned Bool
DispatchQueue.main.async {
self.spinner.isHidden=true;
self.spinner.stopAnimation(self) if(isValid) {
Error ----> if let presenter presenting as? ViewController {
if(isValid) {
presenter.bvalue=false
}
}
}

最佳答案

Every instance of a type has an implicit property called self, which is exactly equivalent to the instance itself. You use the self property to refer to the current instance within its own instance methods.

dourltask() { isValid in 
// do something with the returned Bool
DispatchQueue.main.async {
self.spinner.isHidden=true;
self.spinner.stopAnimation(self) if(isValid) {
if let presenter = self.presenting as? ViewController {
if(isValid) {
presenter.bvalue=false
}
}
}

关于swift - 在任务完成时设置启动器 View Controller 的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46802363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com