== works for NSObject? but not for Equatable?


(Jens Alfke) #1

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?

—Jens

PS: Using Swift 2.1(?), Xcode 7.3


(Jens Alfke) #2

Oh, never mind — I forgot that you can’t compare two Equatable values directly, only two values of the same concrete type that implements Equatable.

I’m still thinking in Objective-C, clearly…

—Jens