'textview search multi words
if the user enters a word in the textview the code works, but if he writes more than one it doesn't work. How can I make the multi-word search work?
hello word IT DOES NOT WORK
hello OK WORK
world OK WORK
let userText = searchTextView.text // hello word
let wordList = ["hello", "word"]
let result = !wordList.contains(where: { !userText.contains($0) })
print(result)
*** I solved the problem, here is the code ***
@IBAction func searchButton(_ sender: Any) {
if searchTextView.text.count != 0 {
let arraySearch = searchTextView.text.lowercased()
let words = arraySearch.components(separatedBy: .whitespacesAndNewlines)
for count in 0...words.count-1 {
let resultWord = words[count]
for str in dataTableWord {
let arrayTableWord = str.word.lowercased()
let range = arrayTableWord.range(of: resultWord)
if range != nil {
dataSearch.append(str)
}
}
}
resultTableView.reloadData()
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
