Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tomaskraina opened this issue Mar 12, 2018 · 0 comments · Fixed by #6845 · May be fixed by #6533
Closed

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

tomaskraina opened this issue Mar 12, 2018 · 0 comments · Fixed by #6845 · May be fixed by #6533

Comments

@tomaskraina
Copy link

tomaskraina commented Mar 12, 2018

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)
@tomaskraina tomaskraina changed the title Comparing two List<String> objects Bug: Comparing two List<String> objects fails Mar 13, 2018
phlippieb added a commit to phlippieb/realm-cocoa that referenced this issue May 25, 2020
Fix realm#5665 by overriding isEqual for RealmSwift.List to compare elements.
@jsflax jsflax added the Breaking label Oct 6, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants