TechnologiesSwiftUINavigation

DefaultNavigationViewStyle struct

iOSmacOStvOSwatchOSvisionOS✓ renders

The default navigation view style.

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.

  1. 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 the NavigationView, declaring that this navigation hierarchy should use the platform's standard presentation.

  2. 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.

  3. Let it govern the NavigationView it wraps

    The style applies to the NavigationView and the navigation chrome inside it. Here it shapes how the List of NavigationLink rows and the .navigationTitle("Home") are presented, choosing a push stack or a split layout as the platform dictates.

  4. 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.

Try it — Replace 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.

DefaultNavigationViewStyle.swift
struct DefaultNavigationViewStyleDemo: View {
    var body: some View {
        NavigationView {
            List {
                NavigationLink("Profile", destination: Text("Profile"))
                NavigationLink("Settings", destination: Text("Settings"))
            }
            .navigationTitle("Home")
        }
        .navigationViewStyle(DefaultNavigationViewStyle())
        .padding()
    }
}
Live preview
Profile Settings 9:41 Home
Profile Settings 9:41 Home
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →