JetSky JetSky - 3 months ago 8
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
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)

    }

    tableView.reloadData()
}

This function searches through the subtitles!

Happy coding!

Comments