Last active
June 20, 2020 14:29
-
-
Save reyandrey/7ce2f606b3898f4b78ab98e2cdd3d133 to your computer and use it in GitHub Desktop.
Coordinator default implementation
This file contains hidden or 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
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