Observable Architecture: Observing Collections

Episode #263 • Jan 8, 2024 • Subscriber-Only

We can now observe struct, optional, and enum state in the Composable Architecture, but what about collections? Let’s explore what it takes to get rid of the ForEachStore wrapper view for a vanilla ForEach view instead, while still observing updates to collection state in the most minimal way possible.

Observing Collections
Getting rid of ForEachStore
Array scope
Minimal observation of collections
New ForEach super powers
Next time: observable navigation

Unlock This Episode

Our Free plan includes 1 subscriber-only episode of your choice, plus weekly updates from our newsletter.


Brandon: 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.

Stephen: 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.

This episode is for subscribers only.

Subscribe to Point-Free

Access this episode, plus all past and future episodes when you become a subscriber.

See plans and pricing

Already a subscriber? Log in