0

I am using the same code displayed in this Stackoverflow URL How do I link the search bar to display results in swift/xcode

and I am wondering if there is also a way to search the detailTextLabel seeing as I have included a subtitle in the cells. The subtitles also do not stay aligned with the textLabels when the filtered search is performed. I am working in Xcode 7.1 and Swift 2.0

Community
  • 1
  • 1
user3203552
  • 53
  • 1
  • 1
  • 5

1 Answers1

0

Yes, you're able to do so. Under the filterContentForSearchText function, simply return the boolean on whether the title or subtitle contains the search string using an '||' operator.

For example,

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()
}
mechdon
  • 517
  • 1
  • 10
  • 23