Skip to main content

The Composable Architecture

The Composable Architecture (TCA, for short) is a library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind. It can be used in SwiftUI, UIKit, and more, and on any Apple platform (iOS, macOS, iPadOS, visionOS, tvOS, and watchOS).

What problems does TCA solve?

This library provides a few core tools that can be used to build applications of varying purpose and complexity. It provides compelling stories that you can follow to solve many problems you encounter day-to-day when building applications.

State management

Manage the state of your application using simple value types, and share state across many screens so that mutations in one screen can be immediately observed in another screen.

Composition

Break down large features into smaller components that can be extracted to their own isolated modules and be easily glued back together to form the feature.

Side effects

Let certain parts of the application talk to the outside world in the most testable and understandable way possible.

Testing

Not only test a feature built in the architecture, but also write integration tests for features that have been composed of many parts, and write end-to-end tests to understand how side effects influence your application.

Core concepts

To build a feature using the Composable Architecture you define some types and values that model your domain:

State

A type that describes the data your feature needs to perform its logic and render its UI.
@ObservableState
struct State: Equatable {
  var count = 0
  var numberFact: String?
}

Action

A type that represents all of the actions that can happen in your feature, such as user actions, notifications, event sources and more.
enum Action {
  case decrementButtonTapped
  case incrementButtonTapped
  case numberFactButtonTapped
  case numberFactResponse(String)
}

Reducer

A function that describes how to evolve the current state of the app to the next state given an action. The reducer is also responsible for returning any effects that should be run, such as API requests, which can be done by returning an Effect value.
var body: some Reducer<State, Action> {
  Reduce { state, action in
    switch action {
    case .incrementButtonTapped:
      state.count += 1
      return .none
    case .decrementButtonTapped:
      state.count -= 1
      return .none
    // ...
    }
  }
}

Store

The runtime that actually drives your feature. You send all user actions to the store so that the store can run the reducer and effects, and you can observe state changes in the store so that you can update UI.
let store: StoreOf<Feature>

Benefits

The benefits of using the Composable Architecture are:
  • Instant testability: You will instantly unlock testability of your feature without additional work.
  • Modular design: You will be able to break large, complex features into smaller domains that can be glued together.
  • Consistent patterns: A uniform approach to state mutations instead of scattering logic across observable objects and UI closures.
  • Concise side effects: A clear, expressive way of handling side effects like API requests and database operations.
  • Comprehensive testing: Write unit tests, integration tests, and end-to-end tests with confidence.

Platform support

The Composable Architecture supports:
  • iOS 16+
  • macOS 13+
  • tvOS 16+
  • watchOS 9+
  • visionOS 1+
It works seamlessly with both SwiftUI and UIKit.

Next steps

Installation

Add TCA to your project using Swift Package Manager

Quick start

Build your first feature with a step-by-step guide

Examples

Explore example applications demonstrating TCA patterns

Point-Free videos

Watch the complete video tour of the architecture

Learn more

The Composable Architecture was designed over the course of many episodes on Point-Free, a video series exploring advanced programming topics in the Swift language. You can watch the complete episode collection and a dedicated multipart tour of the architecture from scratch.

Build docs developers (and LLMs) love