Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

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

11 min readJul 19, 2021

--

A bunch of suitcases on display
Um, you’re only leaving for a few days, do you really need all that? (photo credit: arthur-edelmans, unsplash.com)

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

This Tutorial Uses GitHub to host its starter project

--

--

Kenny Dubroff
Kenny Dubroff

Written by Kenny Dubroff

I’m a Full Stack iOS Developer with a passion for writing clean, reusable code.

No responses yet