Building Better iOS Apps with Swift Composable Architecture

A Functional and Testable Approach

Eniela P. Vela
Mac O’Clock

--

Picture by Igor Savelev in Unsplash

Swift Composable Architecture (TCA) is a software architecture pattern that provides a framework for building iOS applications in a functional, reactive and testable way. It was created by Brandon Williams and Stephen Celis from Point-Free, a company dedicated to teaching functional programming in Swift.

TCA is based on three main principles: state management, data flow, and side effect handling. The state is defined as a structure that represents the current state of the application. Data flow is the process of updating the state when an event occurs. And side effect handling is the way to interact with the outside world (such as network requests or database operations) in a pure way.

In TCA, the UI is a pure function of the application state, which means that the UI can be easily tested by providing different states to the function and verifying the output. This approach also makes the UI more declarative and less imperative, leading to less boilerplate and easier maintenance.

Let’s take a look at an example of TCA in action. Suppose we want to build a simple iOS app that displays a list of tasks and allows the user to add new tasks.

--

--

Eniela P. Vela
Mac O’Clock

iOS Developer | Technical Writer | Software Developer @ Apple