I currently have a UITextField
where I can enter a search string and it will return any of the strings in an array that contain that text, in that specific order. However, I want to make it possible to search on every word and ignore the order of the strings in the array.
var results = [String]()
let filterArray = ["Big green bubble", "Red bubble", "A bubble in green", "Small green bubble", "This bubble is green"]
let textString = "green bubble"
for i in 0 ..< filterArray.count {
let checkString = filterArray[i]
let filterRange = (checkString as NSString).range(of: textString, options: .caseInsensitive)
if filterRange.location != NSNotFound {
results.append(checkString)
}
}
print(results) // returns ["Big green bubble", "Small green bubble"]
I wish it would also include "A bubble in green" and "This bubble is green", because it contains every word I am searching for. Any ideas?