简体   繁体   中英

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...

Any help would be appreciated.

Because a UITextField is not a String. Set it's text property (which is a String) instead of the UITextField itself.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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