O'Reilly logo

Swift Programming: The Big Nerd Ranch Guide by John Gallagher, Matthew Mathias

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

Protocol Extension where Clauses

Extensions allow you to add new methods and computed properties to any type, not just types you have defined. Likewise, protocol extensions allow you to add new methods and computed properties to any protocol. However, as we said earlier, the properties and methods you add in a protocol extension can only use other properties and methods that are guaranteed to exist.

Do you remember the built-in protocol Sequence from Chapter 22? It has an associatedtype named Iterator, which must itself conform to IteratorProtocol. And IteratorProtocol has an associatedtype named Element that indicates the type of elements produced by the generator.

When writing a protocol extension on Sequence, there are not ...

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