Instance Method


Asks the delegate if the text field’s current contents should be removed.


optional func textFieldShouldClear(_ textField: UITextField) -> Bool



The text field containing the text.

Return Value

true if the text field’s contents should be cleared; otherwise, false.


The text field calls this method in response to the user pressing the built-in clear button. (This button is not shown by default but can be enabled by changing the value in the clearButtonMode property of the text field.) This method is also called when editing begins and the clearsOnBeginEditing property of the text field is set to true.

If you do not implement this method, the text field clears the text as if the method had returned true.

See Also

Editing the Text Field’s Text

func textFieldShouldReturn(UITextField) -> Bool

Asks the delegate if the text field should process the pressing of the return button.