You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apple Swift version 2.2 (swiftlang-703.0.18.1 clang-703.0.29)
Target: x86_64-apple-macosx10.9
Additional Detail from JIRA
Votes
0
Component/s
Labels
Bug
Assignee
None
Priority
Medium
md5: 4b956b9a294c69ff89786b0f766e9b68
Issue Description:
When you have a Swift class that inherits from NSObject and you implement the == operator.
You don't automatically get the != operator from the standard library, as stated in the documentation.
classTestClass: NSObject { }
func ==(lhs: TestClass, rhs: TestClass) -> Bool {
returntrue
}
leta = TestClass()
letb = TestClass()
a == b// TestClass implementation of == gets calleda != b// Doesn't call TestClass implementation of == and return the inverse. Instead it calls the isEqual function.
The text was updated successfully, but these errors were encountered:
This is correct behavior. NSObject's implementation of == calls isEqual, and it's NSObject's implementation that's used to conform to Equatable. != is defined in terms of Equatable, so it's always going to use that one.
If you want to customize equality for a subclass of NSObject, you have to use NSObject's designated override point for customizing equality, isEqual.
Environment
Apple Swift version 2.2 (swiftlang-703.0.18.1 clang-703.0.29)
Target: x86_64-apple-macosx10.9
Additional Detail from JIRA
md5: 4b956b9a294c69ff89786b0f766e9b68
Issue Description:
When you have a Swift class that inherits from NSObject and you implement the == operator.
You don't automatically get the != operator from the standard library, as stated in the documentation.
The text was updated successfully, but these errors were encountered: