Chapter 25. Equatable, Comparable, and Hashable
You have spent a lot of time now learning to model data. You have explored value types and reference types and the “free” features that you can sometimes get from them, such as compiler-synthesized empty initializers.
You have also seen useful behaviors that are enabled for you when you conform to certain protocols from the Swift standard library.
For example, conforming to CustomStringConvertible
and implementing its required description
property lets you customize how instances of your types will print to the console.
Conforming to Error
allows instances of your types to be thrown as errors from functions that do failable work.
There are other common behaviors that you can unlock by conforming ...
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.