Conforming to 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 a point is less than another point. You accomplish this functionality by conforming to the Comparable protocol.
Open the documentation for Comparable.
Because you have not entered Comparable yet (so cannot Option-click on its name), click on the Help menu and select Documentation and API Reference.
Search for “Comparable” to determine what is needed.
You will find that you need to overload one operator: the < infix operator.
Add the following code to your struct to make it conform to Comparable.
Listing 25.7 Conforming to Comparable
struct ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access