Chapter 13. Swift patterns
This chapter covers
- Mocking types with protocols and associated types
- Understanding conditional conformance and its benefits
- Applying conditional conformance with custom protocols and types
- Discovering shortcomings that come with protocols
- Understanding type erasure
- Using alternatives to protocols
In this chapter, you’re going to see some useful patterns that you can apply in your Swift programming. I made sure that these patterns were more Swift-focused, as opposed to a more-traditional OOP focus. We’re focusing on Swift patterns, so protocols and generics take center stage.
First, you’re going to mock existing types with protocols. You’ll see how to replace a networking API with a fake offline one, and ...
Get Swift in Depth 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.