Last active
September 26, 2018 07:19
-
-
Save danlozano/95ae5e3ef28c6e22551f21845ee9cfcc to your computer and use it in GitHub Desktop.
Coordinator Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Coordinator { | |
private(set) var childCoordinators: [Coordinator] = [] | |
func start() { | |
preconditionFailure("This method needs to be overriden by concrete subclass.") | |
} | |
func finish() { | |
preconditionFailure("This method needs to be overriden by concrete subclass.") | |
} | |
func addChildCoordinator(_ coordinator: Coordinator) { | |
childCoordinators.append(coordinator) | |
} | |
func removeChildCoordinator(_ coordinator: Coordinator) { | |
if let index = childCoordinators.index(of: coordinator) { | |
childCoordinators.remove(at: index) | |
} else { | |
Print("Couldn't remove coordinator: \(coordinator). It's not a child coordinator.") | |
} | |
} | |
func removeAllChildCoordinatorsWith<T>(type: T.Type) { | |
childCoordinators = childCoordinators.filter { $0 is T == false } | |
} | |
func removeAllChildCoordinators() { | |
childCoordinators.removeAll() | |
} | |
} | |
extension Coordinator: Equatable { | |
static func == (lhs: Coordinator, rhs: Coordinator) -> Bool { | |
return lhs === rhs | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment