Search code examples
swiftsqlitecore-datanspredicatensmanagedobject

How do you apply a predicate while traversing through a fulfilled NSManagedObject?


I'm trying to apply a predicate while traversing through a to-many relationship using a NSManagedObject that has already been fulfilled in a context. I thought about just casting the set as an array and then applying a filter algorithm, but that would trigger a bunch of faults which I don't want as there could possibly be 500+ objects in the set. Is it possible that when accessing this NSSet of faults through the NSManagedObject that I can apply a predicate or a filter to the set and only fulfill those faults?


Solution

  • Filtering the objects in the relationship is correct. It is far more efficient then doing a separate fetch. I have learned this from personal experience with relationship size in the same ballpark (100-2000 entities), and found around a 10 fold speed difference between doing another fetch vs filtering the relationship.