title: Check if Realm list property contains all elements of another list
body: <p>I'm working with iOS/Swift and Realm and I've got a couple of Realm models defined like this:</p>
  
  <pre><code>class Message: Object {
  
      // other properties removed for brevity
  
      var recipients = List&lt;User&gt;()
      var acknowledgedBy = List&lt;User&gt;()
  
      @objc dynamic var fullyAcknowledged = false
  }
  
  class User: Object {
  
      @objc dynamic var id: Int = -1
      @objc dynamic var name: String = ""
  
      convenience init(id: Int, name: String) {
          self.init()        
          self.id = id
          self.name = name
      }
  }
  </code></pre>
  
  <p>My message object has a <code>recipients</code> property that will hold a list of users that this message should be sent to.  When a user receives the message, they'll acknowledge it and that user will then be added to the <code>acknowledgedBy</code> list on the message.  Each time a user is added to the <code>acknowledgedBy</code> list, I need to check to see if everyone who should have received the message has acknowledged it.  When that condition is met, I'll set the <code>fullyAcknowledged</code> property of the message to true.</p>
  
  <p>To check if the message has been acknowledged by everyone, I know I could iterate through each user in <code>recipients</code> and then check if that user is also in the <code>acknowledgedBy</code> list.  I also thought that I could probably accomplish this via the following two-step process:</p>
  
  <ol>
  <li>Compare the element count in <code>recipients</code> and <code>acknowledgedBy</code> to make sure that they're the same; if they are...</li>
  <li>Sort both lists and then compare them to determine if they contain the same users</li>
  </ol>
  
  <p>But I'm wondering if there's a more efficient way to determine that one list contains all the elements of another list (even if they're not in the same order)?</p>
  
  <p>EDIT ----------</p>
  
  <p>It looks like I might also be able to use Sets to make this determination like so:</p>
  
  <pre><code>let ackSet = Set(message.acknowledgedBy)
  let recipientSet = Set(message.recipients)
  let fullyAcknowledged = ackSet.isSubset(of: recipientSet)
  </code></pre>