November 2016
Intermediate to advanced
480 pages
14h 42m
English
Comparable actually inherits from Equatable. You may be able to guess the implication of this inheritance. To conform to the Comparable protocol, you must also conform to the Equatable protocol by supplying an implementation of the == operator. This relationship also means that a type does not have to explicitly declare conformance to Equatable if it declares conformance to Comparable. Remove the explicit declaration of conformance to Equatable from your Point struct.
Listing 25.10 Removing the unnecessary conformance declaration
... struct Point:Equatable,Comparable { let x: Int let y: Int static func ==(lhs: Point, rhs: Point) -> Bool { return (lhs.x == rhs.x) && (lhs.y == rhs.y) } static func <(lhs: ...
Read now
Unlock full access