April 2026
Intermediate
683 pages
25h 29m
English
In Swift, protocol extensions have a unique place among extension types. As you should remember from Chapter 10, protocols act as blueprints for other data types. They don’t contain implementation code by default.
However, protocol extensions offer the unique capability to add default implementations for protocol requirements! That way, you can transform any protocol into an abstract class, offering a partial implementation. How cool is that?
To begin the next demonstration, check the initial Artwork protocol in Listing 11.9. It’s nothing fancy, really—just a protocol with three properties. An Artwork implementation might be a book, painting, or song, for instance.
protocol Artwork { var name: String { get } var
Read now
Unlock full access