My core data model has an entity with an attribute setOfStrings
of type Transformable
.
The corresponding class has a property @NSManaged var setOfStrings: Set<String>?
.
I want to fetch objects using a predicate that filters out objects where their attribute setOfStrings
has a set intersection with a given set, say givenSet
.
I tried to use the following predicate:
NSPredicate(format: "ANY setOfStrings IN %@", givenSet)
but it always evaluates to false
.
If I out comment this predicate, the unfiltered objects are correctly fetched.
I read many SO Q/A related to this subject, e.g. this one. However it does not work.
I know, if my attribute setOfStrings
would be a relation, I could use a subquery to fetch the right objects, as shown here. But I don’t have a relation, just a set of strings.
I have also read this post that says
I assume that the set is defined as a transformable property, which means that it is stored as a binary archive in the SQLite file. Then the above queries will work at most for objects already loaded into the managed object context, but not against the store file.
This is obviously related to my problem. But the suggested solution to replace a simple set of strings by a to-many relation seems to me too complicated.
Which predicate should I use?