Naming Things: A Cautionary Tale
There is an edge case with protocol extensions that may prove to be a great source of frustration if you are not careful. In the previous section, you added description to the requirements of ExerciseType, added a default implementation, and added a specific implementation to Treadmill that took precedence over the default implementation. This worked correctly because description was required by the ExerciseType protocol. What happens, though, if you write a protocol extension to add a property or method, then add the same property or method (with a different implementation) to a conforming type?
The answer is that it depends on how the instance is being accessed – does the compiler know its specific ...
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