Skip to content

Instantly share code, notes, and snippets.

@reyandrey
Last active June 20, 2020 14:29
Show Gist options
  • Save reyandrey/7ce2f606b3898f4b78ab98e2cdd3d133 to your computer and use it in GitHub Desktop.
Save reyandrey/7ce2f606b3898f4b78ab98e2cdd3d133 to your computer and use it in GitHub Desktop.
Coordinator default implementation
protocol CoordinatorProtocol: class {
var completionHandler: (()->())? { get set }
var childCoordinators: [CoordinatorProtocol] { get set }
func start()
}
extension CoordinatorProtocol {
func addChild(_ coordinator: CoordinatorProtocol) {
childCoordinators.append(coordinator)
}
func removeChild(_ coordinator: CoordinatorProtocol) {
childCoordinators = childCoordinators.filter { $0 !== coordinator }
}
}
class Coordinator: CoordinatorProtocol {
var completionHandler: (()->())? = nil
var childCoordinators: [CoordinatorProtocol] = []
func start() {
fatalError("should implement in child")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment