Clean-Swift – Overview of the Architecture

Clean-Swift – Overview of the Architecture

Clean-swift architecture is very simple and does not require any additional libraries. It consists of 3 layers that nicely separate views from logic. Find out what makes them special and how they are related to each other.

Clean-Swift – data flow

The flow of information in clean-swift is unidirectional as shown in the image attached below. This means that if, for example, after pressing the button we have to change the value of text field, the information (after pressing the button) should go to interactor that will prepare the model and send it to presenter, which will “enhance” the text by setting the type of font, color, etc. and will pass it as new model to ViewController for displaying.

Data flow chart

ViewController

This layer is responsible for view. It should be as simple as possible, meaning that it should not have any logic. This layer is responsible only for displaying data to the user and collecting interaction from the user. ViewController layer has router class attached to it which is responsible for navigation between views.

Interactor

When it comes to interactions collected from ViewController, every interaction should go to interactor, no matter if the user presses the button or enters text in input, all of these interactions should be sent to this layer specifically. Technically, the entire logic of application lies in this layer. If there is a need of transferring information from other ViewController (e.g. modal one that we display as modal), the information that we want to pass from other ViewController should be sent to the Interactor’s layer specifically.

For clarity and to avoid overloading class with the code, interactor supports itself with support classes, so-called Workers. This is nothing else than a simple class performing some tasks for interactor’s call. Interactor can have any number of workers which can perform operations on databases, retrieve data from API and so on.

Presenter

The layer responsible for preparing what was sent to it by the interactor to display, so putting string into the attributed string, setting the background color of the button, view, etc.

Basically, that’s it. This architecture is very simple to use and at the same time very clear, I encourage to use it.

If you want to learn more, I recommend a website dedicated to this architecture: clean-swift.com. The sample application is located under the link: https://github.com/Holdapp/Clean-Swift-Example

Lukasz - portrait

Łukasz Szyszkowski

iOS/Mac Developer with over 10 years of experience. He doesn’t limit himself only to Apple’s technologies – Python and Ruby are also among the languages he likes to use if needed. When it comes to programming, Łukasz is a problem solver, and he’s always happy to help when others need support. Fan of good cuisine who enjoys experiments in a kitchen. On sunny days, you might find him somewhere on a trail, biking or hiking.

Learn more

How to Send iOS Notifications in Different Languages? Guide to Dynamic Localization

The best way to set a connection between a user, provider, and an app? System notifications. They allow users to get the latest news in no time. This solution is easy to implement in apps dedicated to one market. But it gets complicated when the messages must be displayed in many languages. In such cases, the dynamic localization of remote notifications can be a real game-changer.

Read more

Promises on the Example of PromiseKit in Objective-C

Sooner or later every programmer encounters the problem of synchronous execution of certain actions. For example: get user information from the API, parse server response, save data to the database, update the view, and many others. To make it even more, at some of these stages you still need to deal with error handling. What should you do exactly?

Read more

Project estimation

Let us know what product you want to build and how we can help you.

Why choose us?

Logo Mobile Trends Awards

Mobile Trends Awards 2021

Winning app in
EVERYDAY LIFE

Nagroda Legalnych Bukmacherów

Legal Bookmakers Award 2019

Best Mobile App

Mobile Trends Awards logo

Mobile Trends Awards 2023

Winning app in MCOMMERCE DEVELOPMENT

23

client reviews

Clutch logo