Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can't do what you want with a predicate. </p> <p>The <code>ANY</code> and <code>ALL</code> operators apply to the entity being tested (in this case <code>Entry</code>) and not the contents of the collection (<code>selectedTags</code>). Either operator will return an <code>Entry</code> object that matches any single element of the collection. The <code>ANY</code> operator will return the first match it finds while the <code>ALL</code> operator will return all matches. In neither case will they return an entry that matches every element in the provided collection.</p> <p>(It also looks like you are trying to use actual <code>Tag</code> objects in <code>selectedTags</code>. That will most likely not work either because object compares on classes without dedicated comparison methods usually fail. It is also slow. You need to compare attributes in predicates.)</p> <p>Since you already have the <code>Tag</code> objects you want, to find the candidate related <code>Entity</code> objects, you just have to walk the <code>Tag.taggedEntries</code> relationship. Then you have to find the intersection of all the sets of <code>Entity</code> object to find only those <code>Entity</code> objects that are related to <strong><em>every</em></strong> selected <code>Tag</code> bject. Since there isn't an intersect collections operator, you need a loop. </p> <pre><code>if ([selectedEntries count]&gt;=2) { NSMutableSet *intersectEntries=[[NSMutableSet alloc] initWithCapacity:1]; for (int i=1; i&lt;[selectedTags count]; i++) { if ([intersectEntries count]==0) { [intersectEntries unionSet:[[selectedEntries objectAtIndex:(i-1)] valueForKey:@"taggedEntries"]]; } [intersectEntries intersectSet:[[selectedEntries objectAtIndex:i] valueForKey:@"taggedEntries"]]; } } </code></pre> <p>(Note: I didn't test this but it should work.) </p> <p>Now <code>intersectEntries</code> should contain only those <code>Entry</code> objects that are related to every selected tag. </p>
 

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