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

Learn more

Introduction to CloudKit

As it turns out, many young developers have never created applications in the iOS Developer Center. Showing how to do it seems like a good idea, so I decided to prepare presentation about CloudKit and kill two birds with one stone.
Read more

Notifications in iOS 10

The new version of iOS introduces a number of changes concerning both local and server notifications. We can use a new framework, UserNotifications, which enables both delivering and handling notifications.
Read more

Visual Memory Debugging with Xcode 8

Nowadays, there are tools that help us a lot to manage the memory when creating apps. Because of that, most software developers rarely encounter memory problems (or are simply unaware of them). However, every once in a while, we have to face some memory leaks. What do we do then? The most common method is to activate the Instruments tool and debug the problem, which can often be quite laborious. With the release of the new Xcode 8, Apple has introduced a new tool which significantly facilitates that – Visual Memory Debugger.
Read more

Project estimation

Check out how we use our knowledge in practice, and make your project with us.

Why choose us?

Logo Mobile Trends Awards

Mobile Trends Awards 2017

Nomination in M-commerce category

17

clients reviews

Clutch logo
Logo Legalni bukmacherzy

Legal Bookmakers Award 2019

Best Mobile App

60+

projects in portfolio