Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a Coordinator protocol with a start method.
iOS Swift
protocol Coordinator {
func [1]()
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names like begin or run instead of start.
Forgetting to declare the method in the protocol.
✗ Incorrect
The Coordinator pattern requires a start() method to begin navigation flow.
2fill in blank
mediumComplete the code to declare a UINavigationController property in the MainCoordinator class.
iOS Swift
class MainCoordinator: Coordinator { var navigationController: [1] func start() { // Implementation } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using UIViewController instead of UINavigationController.
Confusing UITabBarController with navigation controller.
✗ Incorrect
The Coordinator holds a UINavigationController to manage navigation stack.
3fill in blank
hardFix the error in the start method to push a ViewController instance onto the navigation stack.
iOS Swift
func start() {
let vc = ViewController()
navigationController.[1](vc, animated: true)
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using present instead of pushViewController causes modal presentation.
Using addChild is for child view controllers, not navigation.
✗ Incorrect
To navigate in a UINavigationController, use pushViewController(_:animated:).
4fill in blank
hardFill both blanks to declare a child coordinator and add it to the childCoordinators array.
iOS Swift
class MainCoordinator: Coordinator { var childCoordinators = [Coordinator]() func startChild() { let child = ChildCoordinator(navigationController: navigationController) childCoordinators.[1](child) child.[2]() } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using remove instead of append to add child coordinators.
Calling stop instead of start on the child coordinator.
✗ Incorrect
Child coordinators are added with append and started with start().
5fill in blank
hardFill all three blanks to remove a child coordinator from the array by identity.
iOS Swift
func childDidFinish(_ child: Coordinator) {
if let index = childCoordinators.firstIndex(where: { $0 [1] child }) {
childCoordinators.[2](at: index)
}
print("Coordinator [3] finished")
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of === for identity comparison.
Using remove() without index causes error.
Printing wrong status message.
✗ Incorrect
Use === to check identity, remove(at:) to remove, and print 'removed' message.