🎉 Black Friday Sale! Save 30% when you subscribe today.

Tour of the Composable Architecture: Domain Modeling

Episode #247 • Aug 28, 2023 • Subscriber-Only

We’ll learn how to precisely model navigation in the Composable Architecture using an enum to eliminate impossible runtime states at compile time. And we’ll begin to implement the app’s most complex screen and most complex dependency: the record meeting view and the speech client.

Collection
The Composable Architecture
Tour of the Composable Architecture: Domain Modeling
Locked

Unlock This Episode

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

Sign in with GitHub

Introduction

Brandon

And as more types of navigation are added, the number of invalid states really explodes. Four navigation destinations have only 5 valid states, all nil or exactly one non-nil, yet for optionals have 16 possible states. So 70% of the states are completely invalid. And if there were 5 navigation destinations, then over 90% of the states would be invalid!

Stephen

What we are seeing here is that representation multiple navigation destinations with multiple optionals is just not the right way to handle this. Luckily Swift has an amazing tool for dealing with this situation, and it is enums! Enums are the perfect tool for representing the mutually exclusive choice of one thing from many, which is exactly what we want here.

With just a little bit of upfront work we can refactor our domain to use enums instead of many optionals, and the code will become clearly, more succinct and safer.

So let’s give it a shot.

Enum presentation state


References

Downloads

Get started with our free plan

Our free plan includes 1 subscriber-only episode of your choice, access to 64 free episodes with transcripts and code samples, and weekly updates from our newsletter.

View plans and pricing