Skip to content

Bug: Comparing two List<String> objects fails #5665

@tomaskraina

Description

@tomaskraina

Goals

Compare 2 List objects with the same items.

Expected Results

The objects should be equal.

Actual Results

The objects are not equal.

Steps to Reproduce

  1. Create 2 List objects.
  2. Append the same Array to them
  3. Compare them

Code Sample

class RealmExampleTests: XCTestCase {
    
    func testRealmListOfStringsComparison() {
    
        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")
    }
    
}## Version of Realm and Tooling

Realm framework version: 3.1.1
Realm Object Server version: N/A
Xcode version: 9.2
iOS/OSX version: 10.12.6
Dependency manager + version: CocoaPods 1.3.1

ProductName:	Mac OS X
ProductVersion:	10.12.6
BuildVersion:	16G1114

/Applications/Xcode-9.2.app/Contents/Developer
Xcode 9.2
Build version 9C40b

/Users/tomkraina/.rbenv/shims/pod
1.3.1
Realm (3.1.1)
RealmSwift (3.1.1)

/bin/bash
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)

/usr/local/bin/carthage
0.18.1
(not in use here)

/usr/bin/git
git version 2.14.3 (Apple Git-98)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions