DevPrep

All topics › SwiftUI

NavigationStack: how do path, navigationDestination and deep links work?

Middle PRO

The gist

NavigationStack (iOS 16) separates navigation data from views. The stack is a collection of values (the path), and navigationDestination(for:) describes which view to build for a value of a given type. NavigationLink(value:) simply appends a value to the path. Since navigation is data, it is driven programmatically: push is append, pop is removeLast, back to root is clearing it, a deep link is assigning a whole new path.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store