0
0
iOS Swiftmobile~10 mins

Coordinator pattern in iOS Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Astart
Brun
Claunch
Dbegin
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names like begin or run instead of start.
Forgetting to declare the method in the protocol.
2fill in blank
medium

Complete 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'
AUIWindow
BUIViewController
CUITabBarController
DUINavigationController
Attempts:
3 left
💡 Hint
Common Mistakes
Using UIViewController instead of UINavigationController.
Confusing UITabBarController with navigation controller.
3fill in blank
hard

Fix 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'
AshowDetailViewController
Bpresent
CpushViewController
DaddChild
Attempts:
3 left
💡 Hint
Common Mistakes
Using present instead of pushViewController causes modal presentation.
Using addChild is for child view controllers, not navigation.
4fill in blank
hard

Fill 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'
Aappend
Bstart
Cremove
Dstop
Attempts:
3 left
💡 Hint
Common Mistakes
Using remove instead of append to add child coordinators.
Calling stop instead of start on the child coordinator.
5fill in blank
hard

Fill 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'
A===
Bremove
Chas
Dremoved
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of === for identity comparison.
Using remove() without index causes error.
Printing wrong status message.