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

Coordinate your app

Aydar
February 27, 2018

Coordinate your app

Introduction to Coordinator's approach for resolving navigation in iOS applications.
Presented on internal tech talks at Freeletics.

Aydar

February 27, 2018
Tweet

More Decks by Aydar

Other Decks in Programming

Transcript

  1. • Intro to iOS navigation • Problems • Classic solution

    • Solution with Coordinators • Demo Agenda
  2. • Intro to iOS navigation • Problems • Classic solution

    • Solution with Coordinators • Demo
  3. • Intro to iOS navigation • Problems • Classic solution

    • Solution with Coordinators • Demo
  4. E new D E new new D C Problems A

    B C visible Push next A B visible +1 +n
  5. D E C E D Problems A B C visible

    Go back A B visible -1 -n
  6. • Intro to iOS navigation • Problems • Classic solution

    • Solution with Coordinators • Demo
  7. D Classic solution ... func showNext() { let vc: UIViewController

    if isOneFlow { vc = E() } else { vc = P() } push(vc) } ... Chained navigation
  8. • Intro to iOS navigation • Problems • Classic solution

    • Solution with Coordinators • Demo
  9. Solution with Coordinators E D A B C Coordinator 1.

    done 2. init push 3. done 4. init push
  10. Solution with Coordinators E D A B C Coordinator 1.

    done 2. init push 3. done 4. init push
  11. Solution with Coordinators B Coordinator private let onDone: () ->

    () ... func donePressed() { onDone() } ... private func configuredA() -> A { let a = A(onDone: { self.navigationController? .push(configuredB()) }) return a } private func configuredB() -> B { let b = B(onDone: { self.navigationController? .push(configuredC()) }) return b } …
  12. Solution with Coordinators Coordinator Child coordinator private func startChildCoordinator() {

    let coord = ChildCoordinator(onFinish: { self.navigationController?.dismiss() }) navigationController?.present(coord.start()) } init(onFinish: @escaping () -> ()) { self.onFinish = onFinish } ... private func configuredI() -> I { let i = I(onDone: { self.onFinish() }) return i }
  13. Solution with Coordinators +1 +n E D A B C

    Coord A onDone() push(e) visible -1
  14. Solution with Coordinators Coordinator private func startChildCoordinator() { let topVC

    = navigationController!.topViewController let coord = ChildCoordinator(onFinish: { self.navigationController?.pop(to: topVC) }) navigationController?.push(coord.start()) } -n
  15. Solution with Coordinators +1 +n -1 -n Chained navigation Coordinators

    OK, but dependencies OK, but dependencies OK NOT OK OK OK OK OK
  16. • Intro to iOS navigation • Problems • Classic solution

    • Solution with Coordinators • Demo