Generics are used extensively within the Swift standard library and they are what allows the Swift collection types to store instances of any type. To see this, let's go to http://swiftdoc.org/ and look at the Array
type. If you click on the Array link off the main page, you will see the documentation on the Array
type. The documentation will look like this:
At the top of the page, we see that the Array type is defined as struct Array<Element>
. This tells us that the Array type is implemented as a generic value type using a structure. If we now look at the Set, we will see that it is also implemented as a generic structure.