Checking if text fields are empty cause error in S

2019-03-03 09:21发布

I am trying to check if a textbox has no value.

When I do this:

if(userEmail?.isEmpty || userPassword?.isEmpty || userPasswordRepeat?.isEmpty)  

I get the following error enter image description here

I tried adding "?" before the ".isEmpty" but the error won't go away enter image description here

Any ideas?

2条回答
Bombasti
2楼-- · 2019-03-03 09:41

Try this....

if txtEmail.text?.isEmpty == true || txtPassword.text?.isEmpty == true || txtRePassword.text?.isEmpty == true{
        print("true")
}
查看更多
疯言疯语
3楼-- · 2019-03-03 09:42

If interested also in positive case, the following is an alternative solution for Swift 2:

let email = self.txtEmail.text where !email.isEmpty, let password = self.txtPassword.text where !password.isEmpty {
    //all fields are not nil && not empty
}else{
    //some field is nil or empty
}
查看更多
登录 后发表回答