. Realm Equatable :
BOOL RLMObjectBaseAreEqual(RLMObjectBase *o1, RLMObjectBase *o2) {
if ((o1 && ![o1 isKindOfClass:RLMObjectBase.class]) || (o2 && ![o2 isKindOfClass:RLMObjectBase.class])) {
@throw RLMException(@"Can only compare objects of class RLMObjectBase");
}
if (o1 == o2) {
return YES;
}
if (o1 == nil || o2 == nil) {
return NO;
}
if (o1->_realm == nil || o1->_realm != o2->_realm) {
return NO;
}
if (!o1->_row.is_attached() || !o2->_row.is_attached()) {
return NO;
}
return o1->_row.get_table() == o2->_row.get_table()
&& o1->_row.get_index() == o2->_row.get_index();
}
, ) , , Equatable. ) , () , . c) - , , ther .
"" , Realm.
a b . a b ( Realm), .
let a = Blurb()
a.text = "asdf"
let b = Blurb()
b.text = "asdf"
XCTAssertEqual(a.text, b.text)
, Realm . Realm ( "b" ). , , , .
, , :
let a = Blurb()
a.text = "asdf"
let realm = try! Realm()
try! realm.write {
realm.add(a)
}
let b = realm.objects(Blurb.self).first!
print(a == b)