After making sure that the text you want is inside your search bar you can call self.searchBarSearchButtonClicked(searchBar) (passing in your search bar) assuming you have already implemented this UISearchBarDelegate method searchBarSearchButtonClicked(_ searchBar: UISearchBar)