-2
extension tableviewtest: UISearchBarDelegate {
    func searchBar (_ searchBar:UISearchBar, textDidChange searchText: String) {
        searchArr = copiedArray.filter({$0.prefix(searchText.count) == searchText})
        searching = true
        tableview.reloadData()
    }
}

For example, copiedArray has some sentences. ["I love you.", "She's beautiful.", "She's a friend of mine."] when I type "she" into the searchBar, I see the two sentences that start with "she". but when I type "beautiful" or "friend". I don't see anything. How should I solve this?

Cœur
  • 37,241
  • 25
  • 195
  • 267
ssssw
  • 1
  • 5

1 Answers1

2

You can try something like this for non case sensitive search:

copiedArray.filter({$0.lowercased().contains(searchText.lowercased())})

for case sensitive search use this:

copiedArray.filter({$0.contains(searchText)})
Teetz
  • 3,475
  • 3
  • 21
  • 34