This is inside the function, so any textField passed as an argument can respond to the method checkForEmptyFields
:
textField.addTarget(self, action: #selector(checkForEmptyFields(sender:)),
for: UIControlEvents.editingChanged)
This is the method checkForEmptyFields
:
func checkForEmptyFields(sender:UITextField){
self.loginButton.isEnabled = (sender.text?.trim().isEmpty)! == false
}
This is a simple String extension for cropping control:
extension String
{
func trim() -> String
{
return self.trimmingCharacters(in: NSCharacterSet.whitespacesAndNewlines)
}
}
Everything seems to be working fine, but I would like to know if this is correct, and if I forgot something important (or I made some mistake). Thank!
user1094081
source
share