Nominations for the Packages Community Showcase on Swift.org

The Composable Architecture is a fool-proof library that enables (and in a way forces) you to cleanly separate business logic from your UI. In doing so, the UI becomes a simple function that renders your state - with the ability to emit user actions back into the system. It uses a reducer pattern for its architecture, and strongly embraces the concept of state machines.

For us, it's been instrumental in streamlining the development process, parallelising work and testing both UIs and UI logic. In our company we start out defining the state and actions as a team. From there on, we have different parallel paths forward to implement the work.

The engineer assigned to UIs can simply consume a struct representing the state, and call a simple function .send(..) to notify the state machine of user input.
This separates the UI from logic entirely, allowing us to stub states without worrying about the impact of user interactions. Therefore, it actually makes Swift previews usable and easy to implement in large projects. In addition, this allows us to snap screenshots of specific scenarios and record animations from state transitions, such as loading a network request or network request errors. This has previously been a daunting task.

On the opposite side, the same or a separate engineer can implement the business logic. State machines are super maintainable and testable, especially once you get more experienced with them. They force you to specify each side effect using the Effect type, such as asynchronous work. And in doing so, we are able to write tests for every nook and cranny in complex apps. In addition, we're able to utilise the simplicity of this system and its use of concrete types to combine it with multiplayer experiences (using Codable), and save entire user sessions to disk in order to replay bugs.

But aside from all this simplicity and power, it's very remarkable how accessible it's being made with their great API design and even better docs.

30 Likes