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

# searchBar(_:shouldChangeTextIn:replacementText:)

Ask the delegate if text in a specified range should be replaced with given text.

```
optional func searchBar(_ searchBar: UISearchBar, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool
```

## Parameters

`searchBar`

The search bar that is being edited.

`range`

The range of the text to be changed.

`text`

The text to replace existing text in `range`.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if text in `range` should be replaced by `text`, otherwise, <doc://com.apple.documentation/documentation/Swift/false>.

---

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)