Polymorphism with protocols
What we saw in the previous examples is a form of polymorphism. The word polymorphism comes from the Greek root poly, meaning many, and morphe, meaning form. In the programming field, polymorphism is the ability to use a single interface to access multiple types. In the previous examples, the single interface was represented by the Person protocol and the multiple types were any type that conforms to that protocol.
Polymorphism gives us the ability to interact with various types with a standard interface. To illustrate this, we can extend the previous example, where we created an array of the Person types and looped through it. We can then access each item in the array using the interface defined by the Person protocol, regardless of the actual type. Let’s see an example of this, assuming we have an array of Person types named people:
for person in people {
print("\(person.firstName) \(person.lastName):\(person.profession)"...