title: Update property on old Realm object If not exist on new array
body: <p>Hello I have a realm object like bellow. Everytime just before I update realm database I fetch old objects. What I want to do is I want to update removeMe bool to true on all objects which does not exist in new realmObject array. I know this looks like an easy question but I'm searching for the performant way to do it.</p>
  <p>I tried to get diff with NSPrecidate function but it says</p>
  <blockquote>
  <p>Cannot convert value of type 'NSPredicate' to expected argument type
  '(ExampleClass) throws -&gt; Bool'</p>
  </blockquote>
  <pre><code>let predicateFilter = NSPredicate(format: &quot;NOT (primarykey IN %@)&quot;, oldObjects)
  let diff = realmObject.filter(predicateFilter)
  </code></pre>
  <p><strong>EDIT:</strong> To be clear I like to explain what I want to achieve.</p>
  <p>Lets say existing realm objects with primary keys of [A, B, C, D] and my new objects have keys of [A, B, D, F, G] then I want to change existing realm objects removeMe property to true on objects with primary key of [C].</p>
  <p>Visualialize:</p>
  <p><a href="https://i.stack.imgur.com/AfokZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AfokZ.png" alt="enter image description here" /></a></p>
  <p><strong>P.S:</strong> The reason why I use map is because newArrayFromServer is not a realm object and I'm mapping it to realm object to write it to realm database.</p>
  <p>Example Class:</p>
  <pre><code>class ExampleClass: Object {
  @objc dynamic var primaryKey: Int = 0
  @objc dynamic var removedDate: Date?
  @objc dynamic var removedMe: Bool = false 
  override static func primaryKey() -&gt; String? {
      return &quot;primaryKey&quot;
  }   
  }
  </code></pre>
  <p>How I write to Realm Database:</p>
  <pre><code>let oldObjects = Realm.getObjects(ExampleClass.self)
  let realmObject = newArrayFromServer.map { (user) -&gt; ExampleClass in
      let realmUser = ExampleClass(user: user)
      return realmUser
  }
  let realm = try! Realm()
  try! realm.write {
      realm.add(realmObject, update: .modified)
  }
  </code></pre>
  <p>I found a solution which is not that performant. Code below run for loop on old data and check if there is any record which doesn't exist on new response and change the boolean</p>
  <pre><code>let realm = try! Realm()
  let oldRecords = RealmHelper.getObjects(t: ExampleClass.self)
  let newFetchedRecords = backendResponse.map { (newRecord) -&gt; ExampleClass in
      let realmUser = ExampleClass(user: newRecord)
      return realmUser
  }
  oldRecords.forEach { (oldRecord) in
      try! realm.write({
          if newFetchedRecords.contains(oldRecord) == false {
              oldRecord.removedMe = true
          } else {
              oldRecord.removedMe = false
          }
      })
  }
  try! realm.write({
      realm.add(newFetchedRecords, update: .modified)
  })
  </code></pre>