
SwiftUI Cookbook
By :

Some views are designed to be presented in a navigation stack but are not themselves part of a navigation view. One solution to this problem would be to run the application and navigate to the view in question. However, previews provide a time-saving way to figure out how the view would be displayed without running the app.
In this recipe, we will create an app with a view that is part of the navigation stack and preview it in a navigation view.
Let's create a SwiftUI app called PreviewingInNavigationView
.
We will add a NavigationView
and NavigationLink
components to ContentView
that lead to a second view. The second view will not contain a navigation view but will be previewed in one. The steps are as follows:
Text
view in ContentView
with a navigation view containing a VStack
component and NavigationLink
to a view called SecondView
:NavigationView { &...