In Swift 4 I have a CoreData "Sentence" model that has a String attribute "englishsentence". I also have an array of "words" and would like to fetch all sentences for which the "englishsentence" attribute contains one or more of the words in the array.
var words = ["today", "yesterday", "tomorrow"]
This array is just an example. It is supposed to change at runtime and can have any length.
and in the fetch request I am trying to do something like this:
let fetchRequest =
NSFetchRequest<NSManagedObject>(entityName: "Sentence")
let predicate = NSPredicate(format: "ANY englishsentence CONTAINS ANY word IN %@", words)
fetchRequest.predicate = predicate
I am able to create a predicate for all sentences that contain one particular word. However, I cannot get it to work with an array of words unless of course I iterate through the words-array and make a new fetch request for every single word. But this seems awfully inefficient.