Member-only story

Swift Programming Tutorial: Convenience Initializers

Understand Convenience Initializers Like We’re Chatting Over Coffee

Arc Sosangyo
3 min readNov 30, 2024
Photo by taro ohtani on Unsplash

This article is part of my Swift Programming Tutorial series. Make sure you understand classes in Swift before diving into this tutorial.

Imagine this: you’re building a robot. It has a super-duper detailed blueprint (a designated initializer) that tells you exactly what screws, bolts, and circuits you need to build it. But… there are times when you don’t need the whole nine yards! Maybe you’re building a simpler version of the robot for a quick demo. That’s where convenience initializers come in — they’re shortcuts to make your life easier.

Okay, so what’s the deal with these initializers?

In Swift, designated initializers are the “big bosses.” They know everything and can initialize every single property in your class. They’re the ones in charge.

But convenience initializers are like their laid-back assistants. They can call the big boss (or another convenience initializer) and say, “Hey, let’s skip a few steps and just use this preset setup.” They exist purely to save you time when you want to create objects without repeating a bunch of boilerplate code.

--

--

Arc Sosangyo
Arc Sosangyo

Written by Arc Sosangyo

Arc is an iOS Dev and app publisher, a former IT manager who transitioned to iOS engineering, and a big fan of AI, coding, science, history, and philosophy.

No responses yet