SwiftUI and State Management

Section • 3 episodes • 1 hr 18 min

We begin our exploration of application architecture by understanding the core problems that any architecture aims to solve, and we will explore these problems by seeing how SwiftUI approaches state management. This will lead us to formulating the 5 big problems that must be solved, and will guide the development of our architecture from this point forward:

  • How to manage state across an entire application
  • How to model the architecture with simple units, such as value types
  • How to modularize each feature of the application
  • How to model side effects in the application
  • How to easily write comprehensive tests for each feature

Related content

As we’ve seen in this section, SwiftUI is incredibly powerful and is a true paradigm shift in way of building applications. However, some things are still quite difficult to do in SwiftUI, like testing. In this episode we explore how one would test a vanilla SwiftUI application so that we can compare it to testing an application built with the Composable Architecture.

Testable State Management: The Point
33 min

The Composable Architecture unlocks some incredible ways to perform snapshot testing in SwiftUI. We are able to use the Store to play a series of user actions, and then take snapshots of the UI at each step of the way. This gives us lightweight integration testing of our UI with very little work that rivals the tools that Xcode gives us out of the box.

SwiftUI Snapshot Testing
34 min

Where to go from here

Now that we understand the 5 main problems that any architecture should try to solve, and we see how SwiftUI approaches some of those problems, it’s time to chart a course for ourselves. We will begin building our composable architecture from scratch by deciding on the core units that make up the architecture. We will emphasize simplicity by using value types and by making sure they support composition.