TechnologiesSwiftUI

NavigationView struct

iOSmacOStvOSwatchOSvisionOS✓ renders

A view for presenting a stack of views that represents a visible path in a

How it works

A NavigationView presents a stack of views over a navigation context, giving its content a place to push and pop destinations and to display a navigation bar. Reach for it when one view needs to drill down into another — a list of items that leads to a detail screen, for example — so that SwiftUI can manage the back-and-forth transitions and the title bar for you. It establishes the environment that links such as NavigationLink rely on to know where their destinations should appear.

  1. Wrap your content in NavigationView

    NavigationView takes a view builder and treats the view you supply as the root of a navigation hierarchy. Here the List of links becomes that root, so everything inside gains a navigation bar and the ability to present pushed destinations.

  2. Drive transitions with NavigationLink

    A NavigationView is what makes NavigationLink actionable: each link describes a destination that the navigation view pushes onto the stack when tapped. The "Inbox" and "Sent" links each carry their own destination view, and NavigationView performs the push and supplies the back button automatically.

  3. Title the bar with navigationTitle(_:)

    The navigationTitle(_:) modifier sets the text shown in the navigation bar that NavigationView provides. Applying it to the root List produces the "Mail" title, while applying it inside each destination — "Inbox" and "Sent" on the detail Text views — updates the bar as the user drills in.

  4. Place destinations along the stack

    Because NavigationView owns a single column of pushed views, the destination attached to each NavigationLink is shown in that column when selected. The Text("Inbox details") destination, for instance, replaces the list region once "Inbox" is activated, with NavigationView keeping the prior screens available behind the back button.

Try it — Add a third NavigationLink("Drafts") with its own Text destination inside the List, then tap it at runtime to watch NavigationView push and title the new screen.

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.

NavigationView.swift
struct NavigationViewDemo: View {
    var body: some View {
        NavigationView {
            List {
                NavigationLink("Inbox") {
                    Text("Inbox details")
                        .navigationTitle("Inbox")
                }
                NavigationLink("Sent") {
                    Text("Sent details")
                        .navigationTitle("Sent")
                }
            }
            .navigationTitle("Mail")
        }
    }
}
Live preview
Inbox Sent 9:41 Mail
Inbox Sent 9:41 Mail
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →