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 ...

Get Swift Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.