<!--
{
  "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/textFieldShouldClear(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UITextFieldDelegate(im)textFieldShouldClear:"
  },
  "title" : "textFieldShouldClear(_:)"
}
-->

# textFieldShouldClear(_:)

Asks the delegate whether to remove the text field’s current contents.

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

## Parameters

`textField`

The text field containing the text.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the text field’s contents should be cleared; otherwise, <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

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`](/documentation/UIKit/UITextField/clearButtonMode) property of the text field.) This method is also called when editing begins and the [`clearsOnBeginEditing`](/documentation/UIKit/UITextField/clearsOnBeginEditing) property of the text field is set to <doc://com.apple.documentation/documentation/Swift/true>.

If you do not implement this method, the text field clears the text as if the 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)