[swift-users] == works for NSObject? but not for Equatable?

Jens Alfke jens at mooseyard.com
Wed Apr 27 12:09:50 CDT 2016

I’m changing some code that uses NSObject to use Equatable instead, and noticed that while I can compare two optional NSObjects for equality, I can’t compare two optional Equatables. That is, if a and b are of type NSObject?, then a==b compiles; whereas if a and b are Equatable?, a==b  fails with “Binary operator ‘==‘ cannot be applied to two ‘Equatable’ operands”.

I’m guessing that somewhere in the Foundation glue library is a definition of ==(NSObject?, NSObject?), whereas the standard library does not have an ==(Equatable?, Equatable?). Should it?


PS: Using Swift 2.1(?), Xcode 7.3

More information about the swift-users mailing list