Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Application Coordinator

Application Coordinator

Anton Hudz

Alexander Saenko

February 23, 2019
Tweet

More Decks by Alexander Saenko

Other Decks in Programming

Transcript

  1. Responsibilities - Controller • Fetch data • Transform it to

    present • Display it • Notify coordinator
  2. How to use • New or existing project • Group

    your project by flows • Flow -> Coordinator
  3. Sample - AppDelegate class AppDelegate: UIResponder, UIApplicationDelegate { var window:

    UIWindow? private let coordinatorFactory = CoordinatorFactory() private lazy var applicationCoordinator: ApplicationCoordinatorOutput = self.make func application(_ application: UIApplication, didFinishLaunchingWithOptions laun configureWindow() return true } } extension AppDelegate { private func configureWindow() { window = UIWindow(frame: UIScreen.main.bounds) applicationCoordinator.start() } private func makeApplicationCoordinator() -> ApplicationCoordinatorOutput { return self.coordinatorFactory.makeApplicationCoordinator(window: window!) } }
  4. Sample - ApplicationCoordinator func start() { window.makeKeyAndVisible() runFlow1() } private

    func runFlow1() { let flow1Coordinator = coordinatorFactory.makeFlow1Coordinator(navigationController: flow1Coordinator.finishFlow = { [weak self, weak flow1Coordinator] in self?.removeDependency(flow1Coordinator) self?.runFlow2() } addDependency(flow1Coordinator) flow1Coordinator.start() } private func runFlow2() { let flow2Coordinator = coordinatorFactory.makeFlow2Coordinator(navigationController: flow2Coordinator.finishFlow = { [weak self, weak flow2Coordinator] in self?.removeDependency(flow2Coordinator) self?.runFlow1() } addDependency(flow2Coordinator) flow2Coordinator.start() }
  5. Sample - Flow Coordinator func start() { showB() } }

    extension Flow2Coordinator { private func showB() { let controllerBOutput = factory.makeControllerB() controllerBOutput.onFinishFlow = { [weak self] in self?.finishFlow?() } controllerBOutput.onNext = { [weak self] in self?.showC() } router.setRoot(module: controllerBOutput) } private func showC() { let controllerCOutput = factory.makeControllerC() controllerCOutput.onBack = { [weak self] in self?.router.popModule(animated: true) } router.push(controllerCOutput, animated: true, completion: nil) } }
  6. Sample - Controller protocol ControllerBOutput: BaseViewType { var onFinishFlow: (()

    -> Void)? { get set } var onNext: (() -> Void)? { get set } } final class ControllerB: BaseViewController, ControllerBOutput { var onFinishFlow: (() -> Void)? var onNext: (() -> Void)? @IBAction private func nextAction() { onNext?() } @IBAction private func finishFlowAction() { onFinishFlow?() } }
  7. ?