Closed alexeychirkov closed 7 years ago
Thanks for getting in touch. The behavior described in your ticket (modification notification even when the values are equal) is a known limitation, and we'd very much like to fix it eventually (see https://github.com/realm/realm-cocoa/issues/3489).
Thanks, I will close this issue
Goals
The goal is to NOT receive a "modification" change when existing RLMObject with primaryKey is updated with the same property value as it has (e.g. the same string)
Expected Results
"Modification" change is not received
Actual Results
"Modification" change is received
Steps to Reproduce
See below
Code Sample
Assume that we have existing
TestEntity
with primaryKey 'testKey
' and name 'testName
'.TestEntity
ViewController
As a result I get the following change output:
insertions [], deletions [], modifications [0]
I am confused, because property had the same value - it means that object was not changed. Receiving "false positive" changes leads to unnecessary UI redraw (e.g. redraw of the tableView cell).
So we have two methods:
addOrUpdateObject
andcreateOrUpdateInRealm
. Is the following is true?addOrUpdateObject
- this method ALWAYS add new object or replace existing which will lead to "insertions" or "modification" changeBut what about
createOrUpdateInRealm
method?How to achieve my goal? Lets say I am refreshing the list of TestEntities from the server and want to store (update) this list to Realm. List is already stored in Realm, so it is possible that all entities are the same, list in sync already. How to update the list without getting "modifications" change?
What I do now:
- (BOOL)isEqualToEntity:(TestEntity *)entity;
inTestEntity
as analogue of- (BOOL)isEqual:(id)object;
but without class name checkisEqualToEntity
with existing stored TestEntities[realm addOrUpdateObjectsFromArray:unmanagedTestEntities];
methodVersion of Realm and Tooling
Realm version: Realm (2.1.0)
Xcode version: 8.1
iOS/OSX version: 10.11.6
Dependency manager + version: Cocoapods 1.0.1