Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 我一直收到这样一个错误:“我的;隐含使用';自我';关闭;使用';赛尔夫';使捕获语义明确化;_Swift - Fatal编程技术网

Swift 我一直收到这样一个错误:“我的;隐含使用';自我';关闭;使用';赛尔夫';使捕获语义明确化;

Swift 我一直收到这样一个错误:“我的;隐含使用';自我';关闭;使用';赛尔夫';使捕获语义明确化;,swift,Swift,我不断地发现这个错误: 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 == "t

我不断地发现这个错误:

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需要更正。

performsgue
是一种方法,您隐式地调用它;显式版本将是
self.performsgue(…)

只需将您的代码行从
performsgue(带有标识符:“welcomeButton”,发送者:self)
更改为
self.performsgue(带有标识符:“welcomeButton”,发送者:self)

“即使我将自我放入代码中”-在哪里?您的代码没有显示所请求的
self
。@rmaddy performsgue(标识符为:“welcomeButton”,发件人:self)调用self.performsgue您在viewcontroller上调用performsgue,但在闭包中它不知道在什么上下文中调用该方法,因此需要告诉它要使用哪个viewcontroller实例,这是self。@RPS1222消息与传递给
发送方的参数无关。请仔细阅读错误消息,上面写着使用
“self”。
,注意点。只有在方法调用
performsgue
前面才能添加带有点的
self.
。仔细阅读错误消息确实有助于猜测错误所在,即使您并不确切知道。@RPS1222,您能将其标记为正确答案吗?