Unlock This Episode
Our Free plan includes 1 subscriber-only episode of your choice, plus weekly updates from our newsletter.
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.
The Composable Architecture is a library for building applications in a consistent and understandable way, with composition, testing and ergonomics in mind.
Learn the essentials of iOS app development by building a fully functional app using SwiftUI.