0
0
iOS Swiftmobile~20 mins

Coordinator pattern in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Coordinator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why use the Coordinator pattern in iOS apps?
Which of the following best explains the main benefit of using the Coordinator pattern in an iOS app?
AIt centralizes navigation logic to keep view controllers simple and focused on UI.
BIt automatically generates UI layouts without coding.
CIt replaces the need for storyboards entirely.
DIt manages app data persistence across launches.
Attempts:
2 left
💡 Hint
Think about how navigation and screen transitions are handled in an app.
ui_behavior
intermediate
2:00remaining
Coordinator navigation flow
Given a Coordinator that starts with a Login screen and then shows a Home screen after successful login, what happens when the user logs in?
iOS Swift
class AppCoordinator: Coordinator {
  func start() {
    showLogin()
  }
  func showLogin() {
    let loginVC = LoginViewController()
    loginVC.onLoginSuccess = { [weak self] in
      self?.showHome()
    }
    navigationController.pushViewController(loginVC, animated: true)
  }
  func showHome() {
    let homeVC = HomeViewController()
    navigationController.pushViewController(homeVC, animated: true)
  }
}
AThe app replaces Login screen with Home screen without animation.
BThe app pushes Login screen, then pushes Home screen on login success.
CThe app shows Login and Home screens side by side.
DThe app pops Login screen and then pushes Home screen.
Attempts:
2 left
💡 Hint
Look at how navigationController is used to push view controllers.
lifecycle
advanced
1:30remaining
Coordinator memory management
What is the main reason to use [weak self] in closures inside a Coordinator?
iOS Swift
loginVC.onLoginSuccess = { [weak self] in
  self?.showHome()
}
ATo prevent a strong reference cycle that causes memory leaks.
BTo make the closure run on a background thread.
CTo ensure the closure runs only once.
DTo allow the closure to modify self even if it is nil.
Attempts:
2 left
💡 Hint
Think about what happens if self holds a strong reference to the closure and vice versa.
navigation
advanced
1:30remaining
Handling child coordinators
In a Coordinator pattern, why do we keep a strong reference to child coordinators?
ATo allow child coordinators to access the parent view controller directly.
BTo enable child coordinators to modify the app delegate.
CTo keep child coordinators alive while they manage their flows and prevent them from being deallocated.
DTo automatically save child coordinator state to disk.
Attempts:
2 left
💡 Hint
Think about what happens if a child coordinator is not strongly referenced.
📝 Syntax
expert
2:00remaining
Correct Coordinator protocol definition
Which option correctly defines a Coordinator protocol with a start() method and a navigationController property?
A
protocol Coordinator {
  var navigationController: UINavigationController? { get }
  func start() -> Void
}
B
protocol Coordinator {
  var navigationController: UINavigationController? { get set }
  func start() -> Int
}
C
protocol Coordinator {
  var navigationController: UINavigationController { get set }
  func start()
}
D
protocol Coordinator {
  var navigationController: UINavigationController { get }
  func start()
}
Attempts:
2 left
💡 Hint
The navigationController should be readable but not necessarily writable. start() returns nothing.