does the search bar must display a result where each of them must contain all the searched words no matter the order in which they were written?

You can create a Set of the given search words and then use filter where all the words in the search text are checked against the story using allSatisfy

let words = Set(searchText.split(separator: " ").map(String.init))
let filtered = array.filter { object in words.allSatisfy { word in object.story.localizedCaseInsensitiveContains(word) } })

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top