Realm: Comparing List of primitive types, e.g.: List<String>

独自空忆成欢 提交于 2019-12-11 03:37:19

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!