Typed data-driven navigation with NavigationStack
- When NavigationStack was introduced with iOS 16, NavigationView was deprecated, and NavigationLink was updated with new functionality. If you use old code with NavigationView, it can be directly replaced with NavigationStack in its simplest form, as we explained in the previous recipe. For more complex cases, Apple has a document with recommendations on how to migrate to NavigationStack and the new NavigationLink functions.
- Two of the most exciting features of NavigationStack are: 1) navigation is driven by data, and 2) we separate the view code from the navigation code. Since the navigation is driven by data, it is possible to implement arbitrary navigation to any of the views in a navigation stack by manipulating the data. This opens the possibility for flexible navigation patterns like the one needed for deep links.
In this recipe, we will create an app to keep track of our favorite foods to illustrate how a typed data-driven navigation...