简体   繁体   English

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

[英]Cannot assign a value of type String to type UITextField

I have a problem with my code: 我的代码有问题:

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

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

    }

When I do this I get the error below: 当我这样做时,我得到以下错误:

Cannot assign a value of type String to type UITextField with the " if CreatePassWord = pwd " line... 无法使用“ if CreatePassWord = pwd”行将String类型的值分配为UITextField类型...

Any help would be appreciated. 任何帮助,将不胜感激。

Because a UITextField is not a String. 因为UITextField不是字符串。 Set it's text property (which is a String) instead of the UITextField itself. 设置它的文本属性(它是一个字符串),而不是UITextField本身。

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

}

EDIT: Since you're likely doing comparison, not assignment, you want to compare the two strings, not assign pwd to the UITextfield. 编辑:由于您可能要进行比较而不是分配,因此您想比较两个字符串,而不是将pwd分配给UITextfield。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM