top of page
Writer's pictureEric Palma

Building an iOS app with Clean Architecture

We’ve built the core business layer of our app as a Swift package following Clean Architecture principles, so what does it look like to actually use it to build an iOS app?


In today’s post we will look at exactly that, and how our use cases are utilized by client code to build a functional iOS app.


In case you haven’t already, head over to our previous article to learn the basics of Clean Architecture and to see how we use it to build a Swift Package containing our app’s business logic.


You can view the entirety of the iOS app code from this post on GitHub: https://github.com/obvios/employee-directory-mobile-app

The Persistence Layer of our iOS App


If you’ll recall from our previous blog post, when developing our use cases, we had to abstract where the Employee data came from. To accomplish this we defined an EmployeeRepository protocol which our use cases depended on for retrieving Employee data.


This abstraction along with the use cases allowed us to build our core business layer code as a separate Swift Package and solely focus on the business rules, not having to worry about details such as whether data comes from a local file or the network.


However, now that we are building an iOS app, it does matter where this data is coming from. Our use cases still don’t care, but since we are now developing the outer layers, namely the persistence/db layer in this case, this detail does matter.



We are now at the outer layers of clean architecture which are responsible for data persistence, so they must know how data is retrieved and saved. This is where we will create a concrete implementation of the EmployeeRepository protocol.


Below is our implementation. We use a local json file as our persistent storage. It is where we will retrieve employee data and store new data.

With our concrete implementation of the EmployeesRepository protocol, we are ready to move on to the next step.


The UI Layer in SwiftUI

Want to read more?

Subscribe to curiousalgorithm.com to keep reading this exclusive post.

bottom of page