Search code examples
swift3

Swift 3 Why can't Binary operator '===' be applied to two 'Date' operands?


public func ==(lhs: Date, rhs: Date) -> Bool {
  return lhs === rhs || lhs.compare(rhs) == .orderedSame
}

After upgrading to Swift 3 I now get this error... "Binary operator ===cannot be applied to two Date operands"

Any suggestions on how to correct this?


Solution

  • In Swift 3 Date is a structure (value type), there is no identities and thus cannot be ==='ed.

    In fact, the Date type already provides a built-in == so you don't need to implement it yourself.