You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
A comprehensive iOS project demonstrating theCoordinator Pattern for navigation management in UIKit apps, including tab bar integration and child coordinators.
What is the Coordinator Pattern?
The Coordinator Pattern separates navigation logic from view controllers, making your code more:
Testable - Navigation logic can be unit tested independently
Reusable - View controllers don't know how they're presented
Maintainable - All navigation logic is centralized in coordinators
Flexible - Easy to change navigation flows without touching view controllers
Project Structure
CoordinatorExample/├── Coordinators/│ ├── MainCoordinator.swift # Main tab navigation coordinator│ ├── LocationsCoordinator.swift # Locations tab coordinator│ └── AccountCoordinator.swift # Child coordinator for account flow├── ViewControllers/│ ├── TabBarViewController.swift # Tab bar setup and coordinator management│ ├── MainViewController.swift # Main tab content│ ├── LocationsViewController.swift # Locations tab content│ ├── AccountViewController.swift # Account screen (managed by child coordinator)│ ├── DetailViewController.swift # Simple detail screen│ └── BottomSheetViewController.swift # Example modal presentation├── Models/│ └── User.swift # Example data model├── AppDelegate.swift└── SceneDelegate.swift # App entry point
Key Features Demonstrated
✅ Tab Bar with Coordinators
Each tab has its own coordinator and navigation stack
// SceneDelegate creates the tab bar controllerwindow?.rootViewController=TabBarViewController()// TabBarViewController sets up coordinators for each tabclassTabBarViewController:UITabBarController{privatevarmainCoordinator:MainCoordinator?privatevarlocationsCoordinator:LocationsCoordinator?overridefunc viewDidLoad(){letmainNavController=UINavigationController()letlocationNavController=UINavigationController() mainCoordinator=MainCoordinator(navigationController: mainNavController) locationsCoordinator=LocationsCoordinator(navigationController: locationNavController) // Configure tab items and start coordinators}}
2. Tab-Specific Navigation
// Each tab has its own coordinator managing its navigation stackclassMainCoordinator:NSObject,Coordinator,UINavigationControllerDelegate{func start(){letvc=MainViewController() vc.mainCoordinator=self vc.title="Main VC" navigationController.pushViewController(vc, animated:false)}func showDetailViewController(){letvc=DetailViewController() vc.mainCoordinator=self vc.title="Some Detail VC" navigationController.pushViewController(vc, animated:true)}}