title: NSPredicate for to-many relationship, where a relationship (NSSet) must contain Entities defined in an NSArray
body: <p>Given the following Core Data Model:</p>
  
  <pre><code>-&gt; : to-one releationship  
  -&gt;&gt;: to-many relationship
  
  Entity A -&gt;&gt; Entity B 
  Entity B -&gt; A // each B belongs to exactly one A  
  Entity B -&gt;&gt; B // a B can be related to other B's
  </code></pre>
  
  <p>So in class <code>A</code>:</p>
  
  <pre><code>@property (nonatomic, retain) NSSet *Bs;
  </code></pre>
  
  <p>In class <code>B</code>:  </p>
  
  <pre><code>@property (nonatomic, retain) A *A;  
  @property (nonatomic, retain) NSSet *Bs; 
  </code></pre>
  
  <p>Assume I have an <code>NSArray *myArray</code> containing <code>(Bj, Bk)</code>. </p>
  
  <p><strong>What I want is to fetch all <code>B</code>'s which belong to <code>Ax</code> and are related to <code>Bj</code> and <code>Bk</code></strong>:</p>
  
  <p>The code below works, but is completely ugly, since I have to hardcode the NSPredicate based on the number (here it's 2, but it could be 10 or so) of <code>B</code>'s in the array:</p>
  
  <pre><code>NSEntityDescription *fetchedEntity = [NSEntityDescription entityForName:@"B" inManagedObjectContext:self.managedObjectContext];
  [NSPredicate predicateWithFormat:@"A == %@ and (Bs contains %@) and (Bs contains %@)", Ax, [myArray objectAtIndex:0], [myArray objectAtIndex:1]];
  </code></pre>
  
  <p><strong>How can I rewrite the predicate so that it is more generic?</strong> It must be so obvious, but I just don't see it...</p>