🎉 Black Friday Sale! Save 30% when you subscribe today.
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
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.
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.
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.