How to create a Core Data predicate to test that a relation contains all given objects?

后端 未结 2 1941
一整个雨季
一整个雨季 2020-11-27 22:39

Setup:

I have a Core Data object A that has a to-many relation to B. Call the relation \"items\". So, a.items returns all B-s associated with A.

Now, I have

2条回答
  •  自闭症患者
    2020-11-27 23:16

    Have you tried:

    NSPredicate *predicate = [NSPredicate predicateWithFormate:@"items == %@", itemSet];
    

    Alternatively, pull out a subset with a simpler predicate and filter them outside of the fetch request. i.e.

    1. Set a predicate for the number of items in the relationship to the be the same as the number of items in your comparison set.
    2. Fetch the results
    3. Filter these results to show only the ones where the sets contain the same items.

提交回复
热议问题