O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Subclassing Generic classes

In Swift, it is possible to subclass a Generic class. Suppose that we have a Generic Container class. There are two different ways to subclass it. In our first example, GenericContainer subclasses the Container class and stays as a Generic class. In our second example, SpecificContainer subclasses Container and becomes a Container of Int; therefore, it is not Generic anymore:

class Container<Item> { } // GenericContainer stays generic class GenericContainer<Item>: Container<Item> { } // SpecificContainer becomes a container of Int type class SpecificContainer: Container<Int> { } 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required