iOS Implementation


Example

First, make your class comply with the UISearchResultsUpdating protocol.

class MyTableViewController: UITableViewController, UISearchResultsUpdating {}

Add the search controller property:

class MyTableViewController: UTableViewController, UISearchResultsUpdating {
    let searchController = UISearchController(searchResultsController: nil)
}

Add the search bar:

override func viewDidLoad() {
    super.viewDidLoad()

    searchController.searchResultsUpdater = self
    searchController.hidesNavigationBarDuringPresentation = false
    searchController.dimsBackgroundDuringPresentation = false
    searchController.searchBar.sizeToFit()
    self.tableView.tableHeaderView = searchController.searchBar
}

And finally, implement the updateSearchResultsForSearchController method that comes from the UISearchResultsUpdating protocol:

func updateSearchResultsForSearchController(searchController: UISearchController) {

}