A lightweight, flexible coordinator pattern implementation for UIKit applications, designed to simplify navigation flow management in iOS apps.
GoodUIKitCoordinator provides a robust implementation of the coordinator pattern for UIKit-based iOS applications. It helps you separate navigation logic from view controllers, making your code more maintainable, testable, and easier to understand.
- Simplified navigation flow management
- Support for complex navigation hierarchies
- Easy parent-child coordinator relationships
- Built-in support for common navigation actions (push, pop, present, dismiss)
- Integrated support for Safari, universal links, and system apps
- Messaging capabilities (SMS, email)
- Combine integration for reactive programming
- iOS 13.0+ / macOS 11.0+
- Swift 6.0+
- Xcode 15.0+
Add GoodUIKitCoordinator to your project through Swift Package Manager:
- In Xcode, select File > Add Package Dependencies...
- Enter the repository URL:
https://github.com/GoodRequest/GoodUIKitCoordinator.git
- Select the version or branch you want to use
Alternatively, add it to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/GoodRequest/GoodUIKitCoordinator.git", from: "1.0.0")
]
- Create a coordinator by subclassing
GoodCoordinator
with your custom step enum:
// Define your navigation steps
enum AppStep {
case dashboard
case profile
case settings
case details(item: Item)
}
// Create your coordinator
class AppCoordinator: GoodCoordinator<AppStep> {
override func navigate(to step: AppStep) -> StepAction {
switch step {
case .dashboard:
let viewController = DashboardViewController()
return .push(viewController)
case .profile:
let viewController = ProfileViewController()
return .present(viewController)
case .settings:
let viewController = SettingsViewController()
return .push(viewController)
case .details(let item):
let viewController = DetailsViewController(item: item)
return .push(viewController)
}
}
}
- Initialize and start your coordinator:
let navigationController = UINavigationController()
let coordinator = AppCoordinator(rootViewController: navigationController)
coordinator.start()
// Navigate to a specific step
coordinator.perform(step: .dashboard)
You can create hierarchies of coordinators for complex navigation flows:
class ProfileCoordinator: GoodCoordinator<ProfileStep> {
// Implementation
}
class AppCoordinator: GoodCoordinator<AppStep> {
override func navigate(to step: AppStep) -> StepAction {
switch step {
case .profile:
let profileCoordinator = ProfileCoordinator(parentCoordinator: self)
profileCoordinator.start()
profileCoordinator.perform(step: .showProfile)
return .none
// Other cases
}
}
}
Use the static execute
method to navigate between coordinators:
// From any view controller
@IBAction func showSettings() {
GoodCoordinator.execute(
step: .settings,
on: SettingsCoordinator.self,
from: coordinator
)
}
GoodUIKitCoordinator is available under the MIT license. See the LICENSE file for more info.