Search code examples
iosswiftuisearchbaruisearchcontroller

Saving searches from searchBar


I have a UISearchController set up in my table VC and works as expected.

However, I want to be able to save the text from searches (i.e. after they press 'search' or 'enter' on keyboard) into an array.

I couldn't find anything relevant here https://developer.apple.com/documentation/uikit/uisearchbar?language=objc and suspect the solution will involve stuff with the keyboard...


Solution

  • You need to implement searchBarSearchButtonClicked: and/or searchBarTextDidEndEditing: on your searchBar's delegate. These method are called whenever the user presses the search button or finishes editing the text in the search bar, respectively