Instance Property


The search bar to install in your interface.


var searchBar: UISearchBar { get }


Before presenting your searchable content, install the search bar somewhere in your view hierarchy. The search bar becomes the starting point for searching your contents. Interactions with the search bar are handled automatically by the UISearchController object, which notifies the object in the searchResultsUpdater property whenever the search information changes.

You can provide a custom search bar by subclassing UISearchController and overriding this property to return your custom implementation. To ensure the correct configuration of your search bar, lazily initialize it when it’s first requested, as shown in the code below.

class CustomSearchController: UISearchController {

    // Mark this property as lazy to defer initialization until
    // the searchBar property is called.
    private lazy var customSearchBar = CustomSearchBar()

    // Override this property to return your custom implementation.
    override var searchBar: UISearchBar { customSearchBar }

See Also

Managing the Search Results

var searchResultsUpdater: UISearchResultsUpdating?

The object responsible for updating the contents of the search results controller.

var searchResultsController: UIViewController?

The view controller that displays the results of the search.

var isActive: Bool

The presented state of the search interface.