Skip to content

[Swift 3.1][NSArray] Add check to isEqual(to:) whether values is _ObjectBridgeable #1002

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

Merged
merged 3 commits into from
May 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Foundation/NSArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
if val1 != val2 {
return false
}
} else if let val1 = object(at: idx) as? _ObjectBridgeable,
let val2 = otherArray[idx] as? _ObjectBridgeable {
if !(val1._bridgeToAnyObject() as! NSObject).isEqual(val2._bridgeToAnyObject()) {
return false
}
} else {
return false
}
}

Expand Down
6 changes: 6 additions & 0 deletions TestFoundation/TestNSArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,12 @@ class TestNSArray : XCTestCase {

XCTAssertFalse(array1.isEqual(nil))
XCTAssertFalse(array1.isEqual(NSObject()))

let objectsArray1 = NSArray(array: [NSArray(array: [0])])
let objectsArray2 = NSArray(array: [NSArray(array: [1])])
XCTAssertFalse(objectsArray1 == objectsArray2)
XCTAssertFalse(objectsArray1.isEqual(objectsArray2))
XCTAssertFalse(objectsArray1.isEqual(to: Array(objectsArray2)))
}

/// - Note: value type conversion will destroy identity. So use index(of:) instead of indexOfObjectIdentical(to:)
Expand Down
18 changes: 18 additions & 0 deletions TestFoundation/TestNSDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,24 @@ class TestNSDictionary : XCTestCase {

XCTAssertFalse(dict1.isEqual(nil))
XCTAssertFalse(dict1.isEqual(NSObject()))

let nestedDict1 = NSDictionary(dictionary: [
"key.entities": [
["key": 0]
]
])
let nestedDict2 = NSDictionary(dictionary: [
"key.entities": [
["key": 1]
]
])
XCTAssertFalse(nestedDict1 == nestedDict2)
XCTAssertFalse(nestedDict1.isEqual(nestedDict2))
XCTAssertFalse(nestedDict1.isEqual(to: [
"key.entities": [
["key": 1]
]
]))
}

func test_copying() {
Expand Down