0Pricing
SwiftUI Academy · Lesson

Programmatic Navigation Paths

Drive navigation with a navigationDestination path.

Programmatic Navigation Paths is a free SwiftUI Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the SwiftUI Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Navigating From Code

Sometimes a tap is not enough. After saving a form you may want to jump screens yourself. SwiftUI lets you drive the stack from code. ⚙️

A Path You Control

Give NavigationStack a path binding. This array is the live list of screens currently pushed, and editing it changes navigation instantly.

@State private var path = NavigationPath()
NavigationStack(path: $path) { HomeView() }

Push by Appending

Append a value to the path and SwiftUI pushes the matching screen. No tap needed, just change the array.

path.append(book)

Routing the Value

A navigationDestination maps each value type in the path to a view, so appended data knows which screen to become.

.navigationDestination(for: Book.self) { book in
    DetailView(book: book)
}

Pop With Remove

Removing the last element pops a screen, exactly like the back button. You stay in full control of the stack from code.

path.removeLast()

Jump Home Instantly

To return all the way to the root, empty the path. Every pushed screen disappears at once, perfect for a Done button. 🏠

path.removeLast(path.count)

Deep Linking

Because the path is just data, you can build it from a URL or notification, pushing several screens so users land deep inside the app.

NavigationPath Holds Mixed Types

A NavigationPath can store values of different types together, letting one stack route books, users, and settings without a shared enum.

Or Use a Typed Array

If every screen shares one type, a plain typed array works as the path and reads a little more clearly than NavigationPath.

@State private var path: [Book] = []

State Drives the Stack

Navigation becomes state. The visible screens always mirror the path array, so your UI stays predictable and easy to reason about.

Test and Restore

Since the path is plain data, you can save it and restore it, recreating exactly where the user left off when they reopen the app.

Quick Check

What happens when you append a value to a NavigationStack path?

Recap: Programmatic Paths

You bind a path to NavigationStack and push or pop screens by editing that array, turning navigation into predictable, testable state. 🎉

Frequently asked questions

Is the “Programmatic Navigation Paths” lesson free?

Yes — the full text of “Programmatic Navigation Paths” is free to read here on the web, and the SwiftUI Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the SwiftUI Academy course, upgrade to CoddyKit PRO.

What will I learn in “Programmatic Navigation Paths”?

Drive navigation with a navigationDestination path. You practise SwiftUI Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start SwiftUI Academy?

No prior experience is required. SwiftUI Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Programmatic Navigation Paths” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this SwiftUI Academy lesson?

Yes. Every SwiftUI Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Pushing Screens with NavigationLink
  2. Passing Data to Detail Views
  3. Toolbar & Navigation Title
  4. Programmatic Navigation Paths
← Back to SwiftUI Academy