Data Modeling Using Enums in Swift Language

Mohammad Azam
2 min readJun 18, 2021

Application domain objects are the building blocks of any system. The domain represents the entities and the connections between entities of the app. The domain is also used to map the real world into our system.

There are many ways of implementing domain objects. In this article I will show you how to implement models using enums.

Struct as Models

Let’s begin with modeling our data as structs and then we will learn how to take the enum route. Consider a scenario, where we are building an application for a conference. Conference domain can have many models, but we are only focusing on the session. A session represents a speaking engagement at a conference. When using a struct we can represent Session model using the following implementation:

As you can see the Session model can be used to represent a lot of different kind of sessions. This includes keynote, workshop, joint session etc. If we want to create a recordable keynote session, we may end up writing the following code.

--

--

Mohammad Azam

Lead instructor at a coding bootcamp. Top iOS mobile instructor on Udemy. Author of multiple books and international speaker. azamsharp.school