Coordinator pattern for navigation flow

6356
0

The Coordinator pattern separates navigation logic from view controllers, promoting reusability and testability. Coordinators own navigation controllers and decide which screens to show based on user actions. Each flow (onboarding, main, settings) has its own coordinator. Child coordinators handle sub-flows, notifying parents when complete. This removes navigation code from view controllers, making them focused on presentation. ViewControllers call coordinator methods instead of pushing directly. For SwiftUI, coordinators work with NavigationStack's programmatic navigation. The pattern scales to complex apps with multiple entry points and deep linking.