Reputation: 5601
If I have a UISearchController
, what is the difference between:
searchController.searchResultsUpdater = self
public func updateSearchResults(for searchController: UISearchController) {
guard let searchText = searchController.searchBar.text else { return }
// Use searchText
}
and
searchController.searchBar.delegate = self
public func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
// /Use searchText
}
Upvotes: 2
Views: 1184
Reputation: 5601
updateSearchResults
is like a superset of textDidChange
.
Both are called when a new text is entered in the searchBox, and when the text is cleared from the search text field
updateSearchResults
gets triggered in 2 more cases:
searchBarTextDidBeginEditing
method found in UISearchBarDelegate
Upvotes: 8