Created
January 12, 2017 16:11
-
-
Save AndreyPanov/8e95a29128405642599b98455283aa61 to your computer and use it in GitHub Desktop.
BaseCoordinator
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 BaseCoordinator { | |
var childCoordinators: [Coordinator] = [] | |
// add only unique object | |
func addDependency(_ coordinator: Coordinator) { | |
for element in childCoordinators { | |
if element === coordinator { return } | |
} | |
childCoordinators.append(coordinator) | |
} | |
func removeDependency(_ coordinator: Coordinator?) { | |
guard | |
childCoordinators.isEmpty == false, | |
let coordinator = coordinator | |
else { return } | |
for (index, element) in childCoordinators.enumerated() { | |
if element === coordinator { | |
childCoordinators.remove(at: index) | |
break | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment