Composable Stacks: vs Trees

Episode #231 • Apr 17, 2023 • Subscriber-Only

It’s finally time to tackle navigation stacks in the Composable Architecture! They are a powerful, new tool in SwiftUI and stray a bit from all the other forms of tree-based navigation we’ve explored. Let’s compare the two styles and see what it takes to integrate stacks into the library’s navigation tools.

vs Trees
Introduction
00:05
Tree- vs stack-based navigation
01:31
A counter feature with effects
16:03
Stack of counters
23:31
Next time: many destinations
45:17

Unlock This Episode

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

Introduction

Brandon: OK, we have now introduced a property wrapper into our navigation tools, first to deal with some potential performance and stack overflow problems, but it also turned out to be the perfect spot for us to squirrel away some extra information so that we could make the tools even better.

Stephen: So, this is all looking great, but we still have yet to discuss what is probably the hottest topic when it comes to navigation on Apple’s platforms, and that’s navigation stacks. In particular, the initializer of NavigationStack that takes a binding to a collection of data which drives the pushing and popping of screens to the stack. This was introduced in iOS 16 and kinda turned everything upside down relative to how navigation had been done in SwiftUI for the 3 years prior.

Stack-based navigation is where you model all the different screens you can drill-down to as a single, flat array of values. When a value is added to the array, a drill-down animation occurs to that screen, and when a value is removed from the array a pop-back animation occurs.

This stack-based style of navigation is in stark contrast with what we like to call “tree-based” navigation, which is what we have been doing so far in this entire series of episodes. In that model, each feature in the application acts as a branching point for all the different places you can navigate to, and then each of those destinations has branches, and on and on and on.

Each style has lots of positives and some negatives, so let’s dig a little deeper into a comparison of the two styles, and see what the Composable Architecture has to say about stack-based navigation.

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

References

Composable navigation beta GitHub discussion

Brandon Williams & Stephen Celis • Monday Feb 27, 2023

In conjunction with the release of episode #224 we also released a beta preview of the navigation tools coming to the Composable Architecture.