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.

https://github.com/AndreyPanov/ApplicationCoordinator

Andrey Panov

July 15, 2016
Tweet

Transcript

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

    ▸ changes… ▸ coordinators ▸ new way ▸ tips&tricks
  2. didSelectRowAtIndexPath: func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { if {

    router.openControllerA() } else if { router.openControllerB() } else if { router.openControllerC() } else if { router.openControllerD() } }
  3. 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 = } }
  4. COORDINATOR?.START() ▸ hard to reuse ▸ every controller knows about

    other controllers ▸ hard to change flow ▸ hard to test
  5. «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
  6. 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 } }
  7. Controller A Controller B Controller C Send [String: AnyObject] String

    Coordinator String [String:AnyObject] Storage
  8. 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
  9. 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