Polymorphism means many forms. In general, the ability to take more than one form is called polymorphism. In an OOP language such as Swift, a polymorphic reference is one that can, over time, refer to instances of more than one class. Let's examine an example of the iOS SDK, UIView.
There are lots of UIView subclasses, including the following:
We can declare a view that can take many forms, such as the following:
var view: UIView view = UIButton() view = UILabel() view = UITextField()
Polymorphism allows us to write a more generic code that works with families of objects rather than writing code for a specific class.
In this example, regardless of which class we initiate, we can access all the ...