December 2018
Intermediate to advanced
414 pages
10h 19m
English
It is possible to provide default implementations for protocols through extensions. Previously, we provided a partial default implementation for the Toggling protocol on a well-known type. But any other type, that would conform to Toggling needs to provide an implementation on isActive. Using another example, let's look at how we can leverage default implementations in protocol extensions without requiring additional conformance work.
Let's work with a simple protocol, Adder, for the sake of the example:
protocol Adder { func add(value: Int) -> Int func remove(value: Int) -> Int}
The Adder protocol declares two methods: add and remove. And, if we remember our math classes well, we can very well declare remove as a ...
Read now
Unlock full access