What each piece is doing (and why) Coordinator (protocol): a tiny interface so all coordinators expose start() and hold a UINavigationController. Thatβs it.
BaseCoordinator (optional): just avoids copy-pasting child-coordinator bookkeeping (childCoordinators, add/remove). You can delete it if you donβt need multiple nested flows.
AuthCoordinator.onFinish: this is the output of the auth flow. The parent (AppCoordinator) needs to know βlogin succeeded/cancelledβ to switch to Main. We use a callback so Auth doesnβt call parent APIs directly (decoupling + easy to unit test).
Bridge: LoginViewController.onLogin β AuthCoordinator.onFinish(.success) β AppCoordinator swaps to Main.
MainCoordinator.onLogout: the mirror of the above. βUser wants out,β bubble that up to the parent so it can swap back to Auth.
Bridge: HomeViewController.onLogout β MainCoordinator.onLogout() β AppCoordinator shows Auth.
Think of VC closures as intent signals (βuser tapped Xβ), and coordinator closures as flow outputs (βthis flow is doneβ). That separation keeps VCs dumb and flows testable.
Ref: https://chatgpt.com/s/t_68dc6754197c819180ce346f11515086
-
βββββββββββββββββ β Coordinator β (protocol) βββββββββ¬ββββββββ β conforms β βΌ ββββββββββββββββββββ β BaseCoordinator β (concrete, child mgmt) βββββ¬ββββββββββ¬ββββ β β β ββββββββββββΌββββ ββββΌβββββββββββ βAppCoordinatorβ βAuthCoordinatorβ ββββββββββββββββ βββββββββ¬βββββββ β βββββΌββββββββββ βMainCoordinatorβ ββββββββββββββββ
SceneDelegate β creates βΌ AppCoordinator (root) β holds strong refs to child coordinators βββ AuthCoordinator ββ presents β LoginViewController βββ MainCoordinator ββ shows β HomeViewController ββ push β DetailsViewController ββ push β SettingsViewController
[App/Scene launch] ββ> SceneDelegate makes UIWindow + UINavigationController ββ> creates AppCoordinator(nav), calls start() ββ> decides by auth state:
if NOT authenticated:
AppCoordinator β starts AuthCoordinator
AuthCoordinator β shows LoginViewController β (start screen)
if authenticated:
AppCoordinator β starts MainCoordinator
MainCoordinator β shows HomeViewController β (start screen)
User taps "Log In" on LoginViewController ββ LoginVC calls onLogin?() ββ AuthCoordinator invokes onFinish(.success) ββ AppCoordinator removes Auth, starts Main ββ MainCoordinator shows HomeViewController
"Details" button β HomeVC.onDetails?() β MainCoordinator.showDetails() β push DetailsVC "Settings" button β HomeVC.onSettings?() β MainCoordinator.showSettings() β push SettingsVC "Log out" button β HomeVC.onLogout?() β MainCoordinator.onLogout?() β AppCoordinator shows Auth again
Ref: https://chatgpt.com/s/t_68dc5be2dc248191aeea8d9c5bd57864