title: Realm object predicate filter is invalid
body: <p>I use predicate to filter the converstions of models. I got the wrong result with Realm filter (0 models though there should be one). After that, I did another check and she showed me that there is one model with these criteria. Please tell me what may be wrong here.</p>
  
  <pre><code>let checkConversations = Array(realm.objects(ChatConversationModel.self)).filter({ $0.lastMessage != nil &amp;&amp; $0.toDelete == false })
      debugPrint("checkConversations", checkConversations.count) received one model (this is the right result).
  
      var conversations = Array(realm.objects(ChatConversationModel.self).filter("lastMessage != nil &amp;&amp; toDelete == false"))
  
      debugPrint("conversations", conversations.count) I did not receive any models at all
  </code></pre>
  
  <p>Models:</p>
  
  <pre><code>class ChatConversationModel: Object, Mappable {
  
      /// oneToOne = friend
      enum ChatType {
          case oneToOne, group, nonFriend
  
          var index: Int {
              switch self {
              case .oneToOne:
                  return 0
              case .group:
                  return 1
              case .nonFriend:
                  return 2
              }
          }
      }
  
      @objc dynamic var id = ""
      @objc dynamic var typeIndex = ChatType.oneToOne.index
      @objc dynamic var lastMessage: ChatMessageRealmModel?
      @objc dynamic var lastActivityTimeStamp = 0.0
      @objc dynamic var modelVersion = AppStaticSettings.versionNumber
      let createTimestamp = RealmOptional&lt;Double&gt;()
  
      // for group chat
      @objc dynamic var groupConversationOwnerID: String?
  
      /// for group chat equal card photos
      @objc dynamic var cardInfo: ChatConversationCardInfoModel?
  
      // Local
      @objc dynamic var toDelete = false
  
      override class func primaryKey() -&gt; String? {
          return "id"
      }
  
      convenience required init?(map: Map) {
          self.init()
      }
  
      func mapping(map: Map) {
          if map.mappingType == .fromJSON {
              id &lt;- map["id"]
              typeIndex &lt;- map["typeIndex"]
              lastMessage &lt;- map["lastMessage"]
              lastActivityTimeStamp &lt;- map["lastActivityTimeStamp"]
              createTimestamp.value &lt;- map["createTimestamp"]
              modelVersion &lt;- map["modelVersion"]
              // for group chat
              cardInfo &lt;- map["cardInfo"]
              groupConversationOwnerID &lt;- map["groupConversationOwnerID"]
          } else {
              id &gt;&gt;&gt; map["id"]
              typeIndex &gt;&gt;&gt; map["typeIndex"]
              lastMessage &gt;&gt;&gt; map["lastMessage"]
              lastActivityTimeStamp &gt;&gt;&gt; map["lastActivityTimeStamp"]
              createTimestamp.value &gt;&gt;&gt; map["createTimestamp"]
              modelVersion &gt;&gt;&gt; map["modelVersion"]
              // for group chat
              cardInfo &gt;&gt;&gt; map["cardInfo"]
              groupConversationOwnerID &gt;&gt;&gt; map["groupConversationOwnerID"]
          }
      }
  
  }
  </code></pre>
  
  <p><strong>Update:</strong> When I receive actual conversations, I start comparing which already exists in the application. And looking for ids which are not in the result. Next, I find these irrelevant conversations and put toDelete = false, in order to "safely" delete inactive conversations. Since I listened to a podcast with one of Realm's developers, he advised not to delete an object that can be used. And since when receiving results with backend, any inactive conversation can be active again, so I chose this method. You can view the code for these functions.</p>
  
  <pre><code>private func syncNewConversations(_ conversations: [ChatConversationModel], userConversations: [ChatUserPersonalConversationModel], completion: ((_ error: Error?) -&gt; Void)?) {
          DispatchQueue.global(qos: .background).async {
              let userConversationsIDs = userConversations.map { $0.id }
              DispatchQueue.main.async {
                  do {
                      let realm = try Realm()
                      let userConversationPredicate = NSPredicate(format: "NOT id IN %@", userConversationsIDs)
                      let notActualUserConversations = realm.objects(ChatUserPersonalConversationModel.self).filter(userConversationPredicate)
  
                      let filteredNotActualUserConversations = Array(notActualUserConversations.filter({ $0.lastActivityTimeStamp &lt; $0.removedChatTimeStamp }))
  
                      let notActualConversationIDs = filteredNotActualUserConversations.map { $0.id }
  
                      let notActualConversationPredicate = NSPredicate(format: "id IN %@", notActualConversationIDs)
                      let notActualConversations = realm.objects(ChatConversationModel.self).filter(notActualConversationPredicate)
  
                      let notActualMessagesPredicate = NSPredicate(format: "conversationID IN %@", notActualConversationIDs)
                      let notActualMessages = realm.objects(ChatMessageRealmModel.self).filter(notActualMessagesPredicate)
  
                      try realm.write {
                          realm.add(userConversations, update: true)
                          realm.add(conversations, update: true)
                          for notActualUserConversation in notActualUserConversations {
                              notActualUserConversation.toDelete = true
                          }
                          for notActualConversation in notActualConversations {
                              notActualConversation.toDelete = true
                          }
                          for notActualMessage in notActualMessages {
                              notActualMessage.toDelete = true
                          }
                          completion?(nil)
                      }
                  } catch {
                      debugPrint(error.localizedDescription)
                      completion?(error)
                  }
              }
          }
      }
  </code></pre>