Multiple Initializers in Swift

For your class, or struct (or even enum)

Steven Curtis
4 min readNov 4, 2021
Photo by Lukas Blazek on Unsplash

Prerequisites:

You will need to be familiar with the basics of Swift and able to start a Playground (or similar)

It would also be handy to know about classes and structs

Terminology:

Initialization: the process of preparing an instance of a class, structure, or enumeration for use

Initializer: methods used to create an instance of a particular type

If you want a video version of this article you can take a look

So: Imagine that you’d like to use a reusable cell to either display an image

or some text

What are we to do?

Why not use 2 cells?

Please don’t use 2 different UITableViewCell instances. Please, that’s just wrong because either we aren’t reusing code or it’s just not a good…

--

--

No responses yet