April 2017
Intermediate to advanced
316 pages
9h 33m
English
The where clause can be used to define more complex type constraints, for instance, to conform to more than one protocol with some constraints.
We can specify additional requirements on type parameters and their associated types by including a where clause after the Generic parameter list. A where clause consists of the where keyword, followed by a comma-separated list of one or more requirements.
For instance, we can express the constraints that a Generic type T inherits from a C class and conforms to a V protocol as <T where T: C, T: V>.
We can constrain the associated types of type parameters to conform to protocols. Let's consider the following Generic parameter clause:
<Seq: SequenceType where Seq.Generator.Element: ...
Read now
Unlock full access