How it works
DefaultNavigationViewStyle represents the navigation presentation that SwiftUI chooses automatically for the current platform, size class, and context. Rather than fixing a navigation view to a single appearance, it defers to the system: a stack-based push/pop on compact iPhone layouts, a column-based split on iPad and macOS. Reach for it when you want to opt back into that adaptive default after another style has been applied, or when you want to state the intended behavior explicitly so a navigation view's presentation reads clearly in your code.
Apply the style with navigationViewStyle(_:)
The style takes effect when you pass an instance to the navigationViewStyle(_:) modifier on a NavigationView. In the example,
.navigationViewStyle(DefaultNavigationViewStyle())is attached to theNavigationView, declaring that this navigation hierarchy should use the platform's standard presentation.Construct it with the no-argument initializer
DefaultNavigationViewStyle has a single parameterless initializer,
DefaultNavigationViewStyle()— there are no options to configure because the symbol's whole purpose is to hand presentation decisions back to the system rather than pin them down.Let it govern the NavigationView it wraps
The style applies to the
NavigationViewand the navigation chrome inside it. Here it shapes how theListofNavigationLinkrows and the.navigationTitle("Home")are presented, choosing a push stack or a split layout as the platform dictates.Conform through NavigationViewStyle
DefaultNavigationViewStyle conforms to the NavigationViewStyle protocol, the same protocol that backs alternatives like StackNavigationViewStyle and the column-based styles. Because they share that conformance, swapping
DefaultNavigationViewStyle()for another conforming style is a one-line change at the same modifier site.
DefaultNavigationViewStyle() in the .navigationViewStyle(...) call with StackNavigationViewStyle() and run on iPad to see the adaptive default give way to a forced push-style stack.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct DefaultNavigationViewStyleDemo: View {
var body: some View {
NavigationView {
List {
NavigationLink("Profile", destination: Text("Profile"))
NavigationLink("Settings", destination: Text("Settings"))
}
.navigationTitle("Home")
}
.navigationViewStyle(DefaultNavigationViewStyle())
.padding()
}
}