So, I'm developing an app signUp screen. I'm trying to check each field on the signUp screen to see if it's empty, and if it is, display an error message in a label to the user. I've been using a chain of else-ifs
if ((self.firstNameField.text?.isEmpty) != nil) {
errorLabel.text = "first name missing"
errorLabel.hidden = false
}
else if ((self.lastNameField.text?.isEmpty) != nil) {
errorLabel.text = "last name missing"
errorLabel.hidden = false
}
else if ((self.emailField.text?.isEmpty) != nil) {
errorLabel.text = "email missing"
errorLabel.hidden = false
}
else if ((self.passwordField.text?.isEmpty) != nil) {
errorLabel.text = "password missing"
errorLabel.hidden = false
}
else if ((self.confirmPasswordField.text?.isEmpty) != nil) {
errorLabel.text = "password confirmation missing"
errorLabel.hidden = false
}
else if (self.passwordField.text != self.confirmPasswordField.text) {
errorLabel.text = "Passwords don't match, try again!"
errorLabel.hidden = false
}
//omitted what happens if there are no fields missing
Now, when I run the application with all the textfields empty, the errorLabel displays the message "first name missing". Putting in a first name and pressing the signup button does nothing. I want it to change to "last name missing", but it stays at "first name missing".
(self.firstNameField.text?.isEmpty) != nilwill somehow be false????