title: Simple Core Data query
body: <p>I'm designing a chat application for iOS and I have built the model (any feedback would be appreciated...) which is below, but I'm not sure it's fit for purpose.</p>
  
  <p><a href="https://i.stack.imgur.com/COXY6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/COXY6.png" alt="enter image description here"></a></p>
  
  <p>As per the model above, when I create a new conversation, the sender and receiver would be added to the participant set.</p>
  
  <p>Now when I come to build my master table view, I would like to display only receiver participants (exactly like iMessage does - see picture below), but can't think how to extract only the receivers.</p>
  
  <p><a href="https://i.stack.imgur.com/D9Nu0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D9Nu0.png" alt="enter image description here"></a></p>
  
  <p>I did think about adding a "to" and "from" in the Conversation entity but that feels slightly clunky?.  And whilst having the participants feels a little cleaner, I still can't come up with a simple solution.</p>
  
  <p>My initial thought was to get all conversations and exclude the mainUser (who would be the sender)</p>
  
  <pre><code>NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Conversation"];
  [fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"ANY participants.mainUser == nil"]];
  NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"timestamp" ascending:NO];
  </code></pre>
  
  <p>But that doesn't work because I'm asking for the Conversation which includes both participants.</p>
  
  <p>Maybe there is a design issue here.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Thanks</p>