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

标签 swift macos asynchronous

我正在执行一个异步 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/

相关文章:

ios - Swift - 无需按屏幕即可开始游戏

ios - 如果 pickerVew 的窗口打开,键盘会隐藏文本框

ios - 在一行代码中从 Swift 中的字符串数组构建 CSV

C++/R : clang: error: linker command failed with exit code 1 (use -v to see invocation)

macos - 命令未找到 go — 安装 Go 后在 Mac 上

ios - 带有 macos 目标的 React-Native

c# - 异步/等待简单示例

node.js - 同步多个请求和多个数据库调用

ios - UILabel 不显示变量是否有值

javascript - 如何使用 mongoose 尊重 NodeJS 应用程序中的执行顺序