Protocols
Swift protocols aren’t just bags of common syntax. Protocols incorporate well-defined, focused, testable semantics that grow out of the existence of real-world use cases. There must be a sufficient number of potential use cases to make their existence worthwhile. A good protocol should be applicable to many situations, not just one or two.
You describe protocols using nouns (Error, OptionSet, Integer) and adjectives (typically ending in -ble, like Hashable, Strideable, Indexable). These names express what a conforming type is and what it does. A protocol’s name reads as a meaningful role for its conforming types and reflects its underlying semantics.
Look for opportunities to refactor code into protocols. Watch for repeated or similar ...
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