Comparable
Now that your Point
type conforms to the Equatable
protocol, you may be interested in more nuanced forms of comparison.
For example, perhaps you want to know if one point is less than another point.
As with equality, types must define for themselves what it means for one instance to be “less than” another.
You define this functionality by conforming to the Comparable
protocol.
Start by reviewing the documentation for Comparable
.
You have not typed it anywhere yet, so you cannot Option-click its name.
Instead, open Xcode’s Help menu and select Developer Documentation.
Search the documentation for “Comparable” and select the result for the Comparable
protocol in the Swift standard library. Under “Conforming to the Comparable Protocol,” ...
Get Swift Programming: The Big Nerd Ranch Guide, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.