I have some multiple textfields, And If all the fields are filled then only I have to call some method else I have to throw alert.
But, even textfields are empty, It is executing condition as false.
if genderTextField.text?.isEmpty == true && weightTextField.text?.isEmpty == true && heightTextField.text?.isEmpty == true {
self.showAlert(withTitle:"Title", withMessage: "Fill all the fields")
} else {
//call some function
}
But, If I print textfields text
po genderTextField.text
▿ Optional<String>
- some : ""
Any suggestions?
||(or) not and - you want the alert if any field is empty. You can also omit the== truesinceisEmptyis a Boolean. I would suggest that you handlenilproperly via a nil coalescing operatorif (genderTextField.text ?? "").isEmpty ...