无法将 String 类型的值分配给 UITextField 类型

Cannot assign a value of type String to type UITextField

我的代码有问题:

var pwd = "okok"
@IBAction func SendPwd(sender: AnyObject) {

    if CreatePassWord = pwd {
        self.performSegueWithIdentifier("segue", sender: nil)

    }

执行此操作时出现以下错误:

Cannot assign a value of type String to type UITextField with the " if CreatePassWord = pwd " line...

如有任何帮助,我们将不胜感激。

因为 UITextField 不是字符串。设置它的文本 属性(这是一个字符串)而不是 UITextField 本身。

if CreatePassWord.text == pwd {
    self.performSegueWithIdentifier("segue", sender: nil)

}

编辑:由于您可能正在进行比较,而不是赋值,因此您想比较两个字符串,而不是将 pwd 分配给 UITextfield。