我试图比较Realm中的2个字符串列表,如下所示:
func testRealmListOfStrings() {
let strings = ["a", "b", "c"]
let list1 = List<String>()
list1.append(objectsIn: strings)
let list2 = List<String>()
list2.append(objectsIn: strings)
// 1. ok
XCTAssertTrue(list1 !== list2, "instances should not be identical")
// 2. fails
XCTAssertTrue(list1 == list2, "instances should be equal by `==` operator")
// 3. fails
XCTAssertTrue(list1.isEqual(list2), "instances should be equal by `isEqual` method")
// 4. ok
XCTAssertTrue(Array(list1) == Array(list2), "instances converted to Swift.Array should be equal")
}
但是,这不能按预期工作。测试在2.
和3.
上失败。
根据how Realm object's Equatable is implemented,这应该按预期工作,但答案并没有说明它在List中的实现方式。