Search code examples
iosswiftrealm

Updated Realm Objects with no actual change are counted in the RealmCollectionChange


If a Realm Object is included in a Realm.add(_:update:) with update set to true, its index is included in the resultant RealmCollectionChange, even when none of its properties changed.

In my case, I'm parsing JSON, which is then turned into my specific Object. Some of these will have been changed, some not, and some will be entirely new. So when I realm.add(possiblyNewOrUpdatedObjects, update: true), Objects whose values didn't change at all are included in the modifications index array.

Is there something I'm missing about this behavior? Why are non-modified Objects considered modified?


Solution

  • At the moment, that's the accepted functionality. If you set a property on an Object, even if it's the same value as before, that still counts as a change modification.

    There's an issue on the Realm Cocoa repo discussing this functionality and if it should be considered a bug that needs fixing. Issue priorities at Realm are determined by how many users ask about it, so please add your support to that issue. :)