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

Introducing Application Coordinators

Introducing Application Coordinators

A lot of developers need to change navigation flow frequently, because it depends on business tasks. And they spend a huge amount of time for re-writing code. We had the same problem in Avito company. From time to time we needed to change registration flow, publication flow, applying vas-services flow, etc. In this talk, I’ll cover our implementation of Coordinators, the creation of a protocol-oriented, testable architecture written on pure Swift without the downcast and, also to avoid the violation of the S.O.L.I.D. principles. I will be discussing how to implement and integrate application coordinators approach in the current projects.



Andrey Panov

July 15, 2016


  1. INTRODUCING APPLICATION COORDINATOR ANDREY PANOV /panovdev /andreypanov apanov@avito.ru

  2. PRESENTATION.START() ▸ navigation flow in the apps ▸ usual way

    ▸ changes… ▸ coordinators ▸ new way ▸ tips&tricks
  3. FLOW…

  4. AUTH FLOW AuthController SignUpController TermsController PhoneListController AddPhoneController VerifyPhoneController Complete Request

  5. didSelectRowAtIndexPath: func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { if {

    router.openControllerA() } else if { router.openControllerB() } else if { router.openControllerC() } else if { router.openControllerD() } }
  6. None
  7. Controller A Controller B Controller C Send [String:AnyObject] String [Options]

    [String:AnyObject] [String:AnyObject] String
  8. prepareForSegue: override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { if segue.identifier

    == "openControllerA"{ let vc = segue.destinationViewController as! ControllerA vc.monkey = } else if segue.identifier == "openControllerB"{ let vc = segue.destinationViewController as! ControllerB vc.tiger = } else if segue.identifier == "openControllerC"{ let vc = segue.destinationViewController as! ControllerC vc.frog = } else if segue.identifier == "openControllerD"{ let vc = segue.destinationViewController as! ControllerD vc.snake = } }

  10. None
  11. COORDINATOR?.START() ▸ hard to reuse ▸ every controller knows about

    other controllers ▸ hard to change flow ▸ hard to test

  13. «So what is a coordinator? A coordinator is an object

    that bosses view controllers around. Taking all of the driving logic out of your view controllers, and moving that stuff one layer up is gonna make your life a lot more awesome.» –Soroush Khanlou
  14. AUTH FLOW AuthController SignUpController TermsController AuthCoordinator Output Output Output Output

  15. PHONE FLOW PhoneListController AddPhoneController VerifyPhoneController PhoneCoordinator Output Output Output Output

  16. OUTPUT PROTOCOL // controller output protocol PhoneListOutput { var selectPhone:

    (Phone -> ())? { get set } var onVerifyPhone: (Bool -> ())? { get set } } // coordinator output protocol PhoneCoordinatorOutput { var finishFlow: (Phone? -> ())? { get set } }
  17. INPUT PROTOCOL // controller output protocol SignUpFlowInput { func conformTermsAgreement(agree:

    Bool) }
  18. onFinish() AuthFlow PhoneFlow start()

  19. Controller A Controller B Controller C Send [String: AnyObject] String

    Coordinator String [String:AnyObject] Storage

  21. Coordinator Storage Router CoordinatorsFactory ControllersFactory

  22. DEMO.RUN()

  23. None

  25. None
  26. COORDINATORS IN PROJECT AuthCoordinator ItemsCoordinator CreateItemCoordinator SettingsCoordinator

  27. None
  28. COORDINATOR.FINISH() ▸ controllers know nothing about other controllers ▸ controllers

    can be easy integrated in different flows ▸ controllers don’t send data to the others ▸ easy to reuse ▸ simplified testing
  29. APPLICATION COORDINATOR PROJECT /AndreyPanov/ApplicationCoordinator

  30. Swift 3

  31. LINKS Coordinators Redux http://khanlou.com/2015/10/coordinators-redux/ Flow Controllers on iOS for a

    Better Navigation Control http://albertodebortoli.com/blog/2014/09/03/flow-controllers- on-ios-for-a-better-navigation-control/ Boundaries In Practice https://speakerdeck.com/ayanonagon/shi-jian-de-boundaries Application Controller http://martinfowler.com/eaaCatalog/applicationController.html