Member-only story
Decoupling code with protocols and delegation
Getting Started with Swift’s Delegate Pattern
You don’t pack the whole house when you go on vacation, you bring a suitcase
Imagine you’re going on vacation. You know exactly where you’re going, how long you’re staying, and the weather pattern is very reliable. You’re super prepared for what’s to come, and you know exactly what you’ll need when you get there. It wouldn’t make sense to pack everything you own and bring it with you, would it? Yet a lot of us do just this when we don’t use the delegate pattern with a protocol.
What you’ll learn in this tutorial:
- What a delegate is
- What a delegator is
- How a protocol can help decouple code
- How the delegate pattern lets you communicate backward
Helpful To Know:
Programmatic UI
Skill Level: Intermediate
High-Level Overviews:
loadViews
, showDetailViewController
, Factory Pattern