Instance Method


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


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



The text field whose return button was pressed.

Return Value

true if the text field should implement its default behavior for the return button; otherwise, false.


The text field calls this method whenever the user taps the return button. You can use this method to implement any custom behavior when the button is tapped. For example, if you want to dismiss the keyboard when the user taps the return button, your implementation can call the resignFirstResponder() method.

See Also

Editing the Text Field’s Text

func textFieldShouldClear(UITextField) -> Bool

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

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software