JetSky JetSky - 1 year ago 76
Swift Question

Can I search subtitle in tableview?

I have 2 labels: Title and Subtitle on each tableview cell. Now I can search for the title. And I want to search subtitle with search bar,

How can I do it?

Here is how my app looks like:

enter image description here

Answer Source
func filterContentForSearchText(searchText: String, scope: String = "All") {
    filteredObjects = objects.filter { object in

  return object.title.lowercaseString.containsString(searchText.lowercaseString) || object.subtitle.lowercaseString.containsString(searchText.lowercaseString)



This function searches through the subtitles!

Happy coding!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download