Skip to main content
Signature

Explore example code

Browse the SearchBox example code on GitHub.

About this widget

A component that performs a text-based .

Examples

Instantiate a SearchBoxConnector.
Swift

Parameters

searcher
Searcher
required
The Searcher that handles your searches.
interactor
SearchBoxInteractor
default: .init()
The logic applied to SearchBox.
searchTriggeringMode
SearchTriggeringMode
default: .searchAsYouType
Defines the event triggering a new search.
  • .searchAsYouType. Triggers a search on each keystroke.
  • .searchOnSubmit. Triggers a search on submitting the query.
controller
SearchBoxController
default: nil
Controller interfacing with a concrete search box view.

Low-level API

If you want to fully control the SearchBox components and connect them manually, you can use the following components:
  • Searcher. The Searcher that handles your searches.
  • SearchBoxInteractor. The logic that handles new search inputs.
  • SearchBoxController. The controller interfacing with a concrete input view.
Swift

Customizing your view

The default controllers, TextFieldController and SearchBarController, work well with UIKit. If you want to use another component, such as a third-party input view, or introduce custom behaviors to UIKit components, you can create a controller that conforms to the SearchBoxController protocol.

Protocol

  • var onQueryChanged: ((String?) -> Void)? Closure you should call when the query is modified.
  • var onQuerySubmitted: ((String?) -> Void)? Closure you should call when the query is submitted.
  • func setQuery(_ query: String?) Function called when the query is modified from the outside.

Implementation example

Swift

SwiftUI

InstantSearch provides the SearchBar SwiftUI view, which you can embed in your views. It uses SearchBoxObservableController as a data model, which implements the SearchBoxController protocol for SwiftUI. SearchBoxObservableController must be connected to the SearchBoxConnector or SearchBoxInteractor like any other SearchBoxController implementation.
Swift
If you prefer to create a custom SwiftUI view that handles the query input, you can directly use the SearchBoxObservableController as a data model. It provides the query property along with the submit function to streamline the design process of your custom SwiftUI view.
Last modified on July 10, 2026