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

Bitrise Tests Made Easier: Update JIRA Issues with Build Number and Forget About Delays in QA Testing

When you trigger Bitrise build with changes and forget to tell QA specialists some essential information, there are two likely scenarios. You waste time waiting for the update from the tester, only you don’t know it’s never coming. Or you get so many questions about builds that you can’t keep up. Sounds familiar? If so, let us tell you about the JIRA issue update that keeps workflow in order.

Read 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

WebSockets on iOS – Real-time Communication That Doesn’t Slow Down the App

When you want to download data for the app, you probably use the API RESTful interface. All it takes is to ask the server for the data and that’s it! This method works well when the app doesn’t need permanent access to new information. But what to do if the content has to be updated in real-time? A delay can make it impossible for the user to buy an item or make a sports bet, for example. But there’s a solution – WebSockets on iOS. Check out why you should implement them, and how to do it.

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 2017

Nomination in
M-COMMERCE category

Logo Legalni bukmacherzy

Legal Bookmakers Award 2019

Best Mobile App

Mobile Trends Awards logo

Mobile Trends Awards 2020

Nomination in SPORTS & RECREATION category

18

client reviews

Clutch logo