Skip to content

Swifty Clean Architecture: Communicating Intent

This collection of articles focuses on architectural ideas to help create a flexible system in Swift. Communicating intent is a good place to start since it should help to introduce you to the project that I will be using to help demonstrate the principles for a clean architecture.

You can checkout the example project to help illustrate the points explored in this article at this commit.

The first thing you likely notice is the name, xcsautobuild. If you’re familiar with Apple’s development tools you may recognise the XCS acronym as Xcode Server; Apple’s build server. The ‘autobuild’ part suggests an automated way to build something and that’s exactly what the system does; it is a tool to automatically build projects in Xcode Server.

The directory structure of the xcsautobuild project.
The directory structure of the xcsautobuild project.

Now take a look at the top level directory. You’ll notice the usual Sources and Tests directories but let’s focus on the App directory inside Sources. Inside are directories separated into different high level features: Bot Management, Bot Templates, and Branch Filter – perhaps features you would expect with a build server tool. Separating the code in this way helps us to communicate the general, high level concepts of the system.

We can get a better understanding of what this system does by exploring the Interactor objects inside these directories*. Better still, we can look at the tests for these Interactors to get a description of this use case which actually compiles.

* Interactor objects encapsulate a single use case for the system; but more on that in another article.

If you open BotSyncingInteractorTests.swift you’ll see a range of tests including:

Imagine inheriting a project like this; where all the use cases of the system are easily discovered and expressed as a set descriptive tests. Communication is such an important aspect of architecture who’s value is often overlooked and it seems to me that an architecture which screams its intent is a great way to help solve this problem.

This is a small victory but there’s so much more value we can get from this architecture. If you look through the Interactors you may notice that they do not depend on any frameworks. In fact, as we will discover next, we can actually compile these objects independently of the system; we’ll find out why this is important and what benefits this will give us.

Published inArchitectureiOS

Be First to Comment

Leave a Reply