15.2 · Coordinators, routers and dependency injection
Two questions shape the codebase more than the choice of UI pattern: who decides which screen comes next, and who decides which object a screen talks to.
Mental model. Screens should report what happened and receive what they need. Someone else decides where to go next and what to hand over.
Who navigates
Coordinators and routers versus SwiftUI navigation.
- What is a coordinator or router, and how does it compare with SwiftUI’s NavigationStack for deciding who owns navigation?
If each screen decides where to go next, screens know about each other and cannot be reused, tested or reordered. A coordinator (or router) takes that job: a…
Who provides
Dependency injection without a framework religion.
- How do you do dependency injection in Swift, and when do you need a container or framework?
Dependency injection (DI) means an object receives the things it depends on instead of creating or looking them up itself. The benefits are testability…
More in Architecture & API design
- 15.1 · MVC, MVVM, MVP, VIPER, RIBs, TCA and Clean, and unidirectional data flow
- 15.3 · Feature modules and boundaries, and strangling a legacy codebase
- 15.4 · throws, Result, typed throws and mapping errors at boundaries
- 15.5 · Designing a Swift API: naming, ownership, documentation and evolution
- 15.6 · SOLID without dogma, and building a platform for many apps
- 15.7 · Effects and cancellation, modelling state, composing reducers
- 15.8 · Closure-based clients, dependency lifetimes, generic repositories and building the graph lazily
- 15.9 · Binary breaks from innocent changes, and what an import exposes
- 15.10 · Types that prevent misuse, error types for libraries, one-shot values and when to trap