Checking if text fields are empty cause error in Swift 2

后端 未结 2 1214
不知归路
不知归路 2021-01-28 13:22

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

When I do this:

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


        
2条回答
  •  梦谈多话
    2021-01-28 13:48

    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
    }
    

提交回复
热议问题