Browse Questions
- The Repository pattern abstracts the data layer behind a protocol.
- The Coordinator pattern moves navigation logic out of ViewControllers into dedicated Coordinator objects.
- Swift's async/await is directly supported in XCTest — mark your test function as async throws and await the result.
- The three modes differ in where the authentication token lives and whether the output grows: Seal appends the token to the ciphertext, Token Protect returns the token separately so the ciphertext…
Answer: The Coordinator pattern moves navigation logic out of ViewControllers into dedicated Coordinator objects. Each coordinator owns a navigation flow.
Why:
- ViewControllers shouldn't know about other ViewControllers
- Enables reuse and deep-linking
- Easier to test navigation flows
Code Example:
protocol Coordinator: AnyObject {
var navigationController: UINavigationController { get }
func start()
}
class HomeCoordinator: Coordinator {
var navigationController: UINavigationController
init(nav: UINavigationController) {
self.navigationController = nav
}
func start() {
let vc = HomeViewController()
vc.coordinator = self
navigationController.pushViewController(vc, animated: false)
}
func showDetail(for item: Item) {
let vc = DetailViewController(item: item)
vc.coordinator = self
navigationController.pushViewController(vc, animated: true)
}
}