The coordinator pattern

Architecture & patterns Mid-level Swift 5.0+ iOS 17+ Reviewed By Alok Singh

Pick the fix

View controllers push each other directly, so the same screen can't be reused in another flow. Fix?

Options
Hint 1 of 1

Who should decide what comes next?

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Add a coordinator that creates screens and handles their callbacks to decide what to show next

Correct. Screens no longer know about each other.

Why not the others?
  • B Use more storyboard segues. Segues still hard-code the next screen.
  • C Use one base view controller with navigation helpers. Navigation is still decided inside screens.
  • D Post notifications to trigger navigation. Global, untyped and hard to follow.

30-second answer

A coordinator owns navigation for a flow: it creates screens, injects their dependencies and decides what comes next, while screens just report events through callbacks. This keeps view controllers reusable and flows testable. In SwiftUI the same idea is a router or navigation model that owns a NavigationPath and maps routes to views.

Practise saying it · 45 s. No recording, just a timer

Explain the coordinator pattern.

Say your answer out loud, then check which of these points you covered:

  • Owns navigation
  • Screens report events
  • Child coordinators
  • SwiftUI router

Deep dive

Child coordinators handle sub-flows like onboarding or checkout.

Remove child coordinators when their flow ends to avoid leaks.

Deep links become a call on the coordinator or router.

Screens expose callbacks such as onSelect rather than pushing.

Common mistakes

  • View controllers pushing each other directly.
  • Coordinators that are never released.

Senior take & follow-ups

Seniors explain ownership of navigation and how it keeps screens decoupled.

Follow-up questions

Think of your answer first, then open the hint.

  1. How do deep links fit?

    Show hint

    Translate the URL into routes on the coordinator.

  2. What's the SwiftUI equivalent?

    Show hint

    A router owning NavigationPath.

Suggest a fix if something here is wrong or out of date.