首页 > 解决方案 > 我不断收到此错误:“在闭包中隐式使用'self';使用'self。' 使捕获语义明确”

问题描述

我不断收到此错误:

Implicit use of 'self' in closure; use 'self.' to make capture semantics explicit

即使我将自我放入代码中。请纠正我。

这是我的代码:

@IBAction func doneButton(_ sender: Any) {
    let code = codeTextField.text
    if code == "TEST" || code == "Test" || code == "test" {
        var myAlert = UIAlertController(title:"Alert", message: "You are logging into The Test Zoo, right?", preferredStyle: UIAlertController.Style.alert)
        let yesAction = UIAlertAction(title: "Yes", style: UIAlertAction.Style.default) {
            UIAlertAction in
            performSegue(withIdentifier: "welcomeButton", sender:self)
        }

还有更多,但 yesAction 需要更正。

标签: swift

解决方案


performSegue是一种方法,您正在隐式调用它self;显式版本是self.performSegue(...).


推荐阅读