Reputation: 13246
Below, d
and dictionary
refer to the same realm object, but both ==
and isEqual:
result in NO
. What is the best method for comparing realm objects that do not have primary keys?
(lldb) po d
UserDictionary {
dateImported = 2016-02-12 03:44:53 +0000;
dirtyProperties = RLMArray <0x7f01a110> (
);
var1 = ingles;
var2 = ;
var3 = ;
name = bab.la (popup);
url = http://en.bab.la/dictionary/%(var1)s-english/%(term)s;
toLanguage = es;
fromLanguage = en;
}
(lldb) po dictionary
UserDictionary {
dateImported = 2016-02-12 03:44:53 +0000;
dirtyProperties = RLMArray <0x7a1b4d30> (
);
var1 = ingles;
var2 = ;
var3 = ;
name = bab.la (popup);
url = http://en.bab.la/dictionary/%(var1)s-english/%(term)s;
toLanguage = es;
fromLanguage = en;
}
This must be done somewhere, because I was able to use indexOfObject in RLMResults as a workaround.
Upvotes: 0
Views: 1484
Reputation: 8138
isEqualToObject:
checks if two object instances refer to the same underlying persisted object.
Upvotes: 3
Reputation: 2591
The default isEqual:
implementation simply compares the memory address, as ==
does.
You must implement the -isEqualToUserDictionary:(UserDictionary*)
yourself.
You can also implement the -isEqual:(id)
method, but you should
check the type of the object first inside the method.
You shouldn't compare the primary key of the object, but all of its fields instead.
Implementing -hash
is a nice way to make your objects comparable.
Upvotes: 2