How to clear the text field automatically
Use this method,
If you want to manually clear the text field use this code:
textField.text = ""
If you want the text field to empty when you begin editing, use the delegate method below:
func textFieldDidBeginEditing(textField: UITextField) {
textField.text = ""
}
If you are using multiple text fields, use the method below:
func textFieldDidBeginEditing(textField: UITextField) {
if (textField == oneTextField) {
textField.text = ""
}
else if (textField == anotherTextField) {
// Perform any other operation
}
}
Simply use textFieldDidBeginEditing
method to handle focus change, and clear text.
func textFieldDidBeginEditing(textField: UITextField) {
textField.text = ""
}
You can easily clear the TextField in swift
emailTextField.text?.removeAll()
passwordTextField.text?.removeAll()
confirmPasswordTextField.text?.removeAll()