O'Reilly logo

Swift Programming: The Big Nerd Ranch Guide by John Gallagher, Matthew Mathias

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Comparable’s Inheritance

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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required