Thanks to the new Observation tools in Swift 5.9 we have now gotten rid of 4 specialized view helpers that previously existed only to aid in minimizing view re-computation. They are WithViewStore
, IfLetStore
, SwitchStore
and CaseLet
. We now get to use simpler, more vanilla Swift code to constructs these views, and they still minimally observe only the state that is touched in the view.
But there’s another really powerful and popular view helper that ships with the library that allows you to decompose complex list-based features into smaller units, and that’s the ForEachStore
. With it you can easily transform a store of some collection of features into individual stores for each element in the collection. This allows you to have a dedicated, isolated Composable Architecture feature for each row in a list.
It would be amazing if we could get rid of this concept too, and just use a vanilla SwiftUI ForEach
view. Well, this is absolutely possible, and it greatly simplifies the way one deals with lists in the Composable Architecture.
Let’s take a look.