For the More Curious: Polymorphism and Protocol-Oriented Programming
In Chapter 15, Structs and Classes, you learned about class inheritance and that any function that expects an argument of some class can also accept arguments that are subclasses of that class. We said that this ability to accept either a class or any subclass of it is sometimes referred to as polymorphism. Polymorphism, meaning “having many forms,” allows you to write a single function that can accept different types.
That particular flavor of polymorphism is more precisely known as runtime polymorphism or subclass polymorphism. Using protocol types as function arguments or return values is another example of runtime polymorphism.
Runtime polymorphism is a powerful tool, ...
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.