<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITextFieldDelegate/textFieldShouldEndEditing(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UITextFieldDelegate(im)textFieldShouldEndEditing:"
  },
  "title" : "textFieldShouldEndEditing(_:)"
}
-->

# textFieldShouldEndEditing(_:)

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

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

## Parameters

`textField`

The text field in which editing is about to end.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if editing should stop or <doc://com.apple.documentation/documentation/Swift/false> if it should continue.

## 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()`](/documentation/UIKit/UIResponder/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 <doc://com.apple.documentation/documentation/Swift/true> from this method to allow the text field to resign the first responder status. You might return <doc://com.apple.documentation/documentation/Swift/false>, however, in cases where your delegate detects invalid contents in the text field. Returning <doc://com.apple.documentation/documentation/Swift/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 ``doc://com.apple.uikit/documentation/UIKit/UITextField``.

Be aware that this method provides only a recommendation about whether editing should end. Even if you return <doc://com.apple.documentation/documentation/Swift/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 <doc://com.apple.documentation/documentation/Swift/true>.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)