Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure I understand your question, but at least I can answer how to get those objects that two Core Data managed objects have in common in a certain property.</p> <p>You have two Core Data entities, <code>A</code> and <code>C</code>. As all Core Data entities, they are represented by <code>NSManagedObject</code> instances at runtime. You have defined <code>A</code> and <code>C</code> to each have a relationship called <code>B</code>, which is one-to-many or many-to-many. In other words, each <code>A</code> object can have many <code>B</code> objects and so can <code>C</code>.</p> <p>To make this a bit easier I will come up with other names for these classes:</p> <pre><code>Dessert &lt;&lt;----&gt;&gt; Ingredient MainDish &lt;&lt;----&gt;&gt; Ingredient </code></pre> <p>Let's say the relationship is called <code>ingredients</code>. You can then get all ingredients for a dessert with</p> <pre><code>NSSet* dessertIngredients = [myDessert valueForKey:@"ingredients"]; </code></pre> <p>And likewise get the ingredients for the main dish like so: </p> <pre><code>NSSet* mainDishIngredients = [myMainDish valueForKey:@"ingredients"]; </code></pre> <p>To get the intersection of the two sets, you need to use a mutable set object:</p> <pre><code>NSMutableSet* commonIngredients = [NSMutableSet setWithSet:dessertIngredients]; [commonIngredients intersectSet:mainDishIngredients]; </code></pre> <p>Another way to get the same result is by using Cocoa's <a href="http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/KeyValueCoding/Articles/CollectionOperators.html" rel="nofollow">KVC collection operator</a> <code>@distinctUnionOfArrays</code>:</p> <pre><code>NSArray* objectsWithIngredients = [NSArray arrayWithObjects:myMainDish, myDessert, anotherMainDish, nil]; NSSet* uniqueIngredients = [anotherMainDish valueForKeyPath:@"@distinctUnionOfArrays.ingredients"]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload