Protocol Extension where Clauses
Extensions allow you to add new methods and properties to any type, not just types you have defined. Likewise, protocol extensions allow you to add new methods and properties to any protocol. However, as we said earlier, the properties and methods you add in a protocol extension can only make use of other properties and methods that are guaranteed to exist.
Do you remember the built-in protocol SequenceType from Chapter 22?
It has a typealias named Generator, which must itself conform to GeneratorType.
And GeneratorType has a typealias named Element that indicates the type of elements produced by the generator.
When writing a protocol extension on SequenceType, there are not very many properties and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access