11.8 Summary
This chapter was about extensions, which empower programmers with the option to add new features to custom data types, as well as to Swift’s built-in types, without modifying the original code. Enums, structs, classes, and protocols can be extended with various components, such as computed properties, functions, initializers, subscripts, nested types, and even protocol conformance.
Protocol extensions are especially curious as they enable partial implementations, making protocols behave like abstract classes.
It’s possible to add operator support via extensions and even to invent custom operators like √. Finally, generics and extensions also work well together when needed.
This chapter concluded our main content on object-oriented ...
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