---
title: "textFieldShouldEndEditing(_:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uitextfielddelegate/textfieldshouldendediting(_:)"
---

# textFieldShouldEndEditing(_:)

Asks the delegate whether to stop editing in the specified text field.

## Declaration

```swift
optional func textFieldShouldEndEditing(_ textField: UITextField) -> Bool
```

## Parameters

- `textField`: The text field in which editing is about to end.

## Return Value

Return Value true if editing should stop or false if it should continue.

## Discussion

Discussion The text field calls this method when it is asked to resign the first responder status. This can happen when the user selects another control or when you call the text field’s resignFirstResponder() method. Before the focus change occurs, however, the text field calls this method and gives you a chance to prevent the change from happening. Normally, you would return true from this method to allow the text field to resign the first responder status. You might return false, however, in cases where your delegate detects invalid contents in the text field. Returning false prevents the user from switching to another control until the text field contains a valid value. note: If you use this method to validate the contents of the text field, you might also want to use an overlay view to provide feedback to that effect. For example, you might display a small icon indicating the text is invalid. For more information about adding overlays to text fields, see the methods of UITextField. Be aware that this method provides only a recommendation about whether editing should end. Even if you return false, UIKit might still force an end to editing. For example, text fields always resign the first responder status when they are removed from their parent view or window. Implementation of this method by the delegate is optional. If you do not implement this method, the text field resigns the first responder status as if this method had returned true.

## See Also

### Managing editing

- [textFieldShouldBeginEditing(_:)](uikit/uitextfielddelegate/textfieldshouldbeginediting(_:).md)
- [textFieldDidBeginEditing(_:)](uikit/uitextfielddelegate/textfielddidbeginediting(_:).md)
- [textFieldDidEndEditing(_:reason:)](uikit/uitextfielddelegate/textfielddidendediting(_:reason:).md)
- [textFieldDidEndEditing(_:)](uikit/uitextfielddelegate/textfielddidendediting(_:).md)
- [UITextField.DidEndEditingReason](uikit/uitextfield/didendeditingreason.md)
