问题
What is the intended way to compare Realm's list of strings?
I'm trying to compare 2 lists of strings in Realm, as follows:
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")
}
However, this does not work as expected. The test fails on 2. and 3..
According to how Realm object's Equatable is implemented this should work as expected although, the answer does not specify how exactly it's implemented in List.
来源:https://stackoverflow.com/questions/49238170/realm-comparing-list-of-primitive-types-e-g-liststring