iOS Developer interview question
How do you structure navigation in a SwiftUI app?
SwiftUI navigation should derive from explicit route state, use stable identifiers and typed destinations, preserve deep-link and restoration behaviour, and keep routing decisions outside reusable views.
Direct answer
What a strong answer covers
How it works
Navigation state is data: a NavigationPath or an array of typed route values owned by a router or the top-level view model, rendered by NavigationStack with navigationDestination for each route type. Screens ask the router to push or present rather than constructing the next view themselves, which keeps them reusable and testable. Deep links parse into the same route values and replace the path, sheets and full-screen covers are driven by optional state, and the path is Codable so it can be persisted for state restoration.
Example
A shopping app defines enum Route: Hashable { case product(id), cart, checkout } and stores [Route] in an @Observable AppRouter; tapping a product appends .product(id), and a universal link for a product sets the path to [.product(id)] so the back button returns to the root. The checkout flow is a separate NavigationStack inside a sheet so it can be dismissed as a unit.
Common mistakes
- Building NavigationLink(destination:) chains that create views eagerly and couple screens to each other.
- Handling deep links by pushing views manually and ending up with an inconsistent back stack.
- Keeping presentation booleans in many views so two sheets can be requested at once.
A useful answer structure
Answer from your own work.
Do not memorise a script: use only examples you can explain honestly in follow-up questions.
Open the desktop workspace and rehearse a clear answer in your own words.