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

Flow Coordinators in iOS

Flow Coordinators in iOS

Example is implemented in Swift.

Link to GitHub example - https://github.com/dimaosa/ApplicationCoordinator

The presentation is based on the following articles:

1. Coordinators Essential tutorial. Part I - https://medium.com/blacklane-engineering/coordinators-essential-tutorial-part-i-376c836e9ba7
2. Coordinators Essential tutorial. Part II -(-https://medium.com/@panovdev/coordinators-essential-tutorial-part-ii-b5ab3eb4a74
3. Coordinators, Routers, and Back Buttons -https://hackernoon.com/coordinators-routers-and-back-buttons-c58b021b32a
4. A series of advanced coordinators - http://khanlou.com/tag/advanced-coordinators/
5. Improve your iOS Architecture with FlowControllers - http://merowing.info/2016/01/improve-your-ios-architecture-with-flowcontrollers/

For more questions ping me in Facebook -> www.facebook.com/dima.osadchy

Dima Osadchy

July 04, 2019
Tweet

More Decks by Dima Osadchy

Other Decks in Programming

Transcript

  1. What is coordinator? A coordinator is an object which handles

    app navigation flow and configures controllers and view models. Controllers don’t know anything about coordinator. They only expose an interface that informs the coordinator when navigation should happen.
  2. Why are coordinators great? 1. Each view controller is now

    isolated. View controllers don’t know anything beyond how to present their data. Whenever anything happens, it tells its delegate, but of course it doesn’t know who its delegate is.
  3. Why are coordinators great? 2. View controllers are now reusable.

    They don’t assume anything about what context they’ll be presented in, or what their buttons will be used for. They can be used and reused for their good looks, without dragging any logic along with them. If you’re writing your iPad version of your app, the only thing you need to replace are your coordinators, and you can reuse all the view controllers. .
  4. Why are coordinators great? 3. Every task and sub-task in

    your app now has a dedicated way of being encapsulated.
  5. Why are coordinators great? 4. Coordinators separate display-binding from side

    effects. You never again have to worry about if a view controller will mess up your data when you present a view controller. It can only read and display, never write or corrupt data. This is a similar concept to command-query separation (Asking a question should not change the answer)
  6. Why are coordinators great? 5. Coordinators are objects fully in

    your control. You’re not sitting around waiting for -viewDidLoad to get called so you can do work, you’re totally in control of the show. There’s no invisible code in a UIViewController superclass that is doing some magic that you don’t understand. Instead of being called, you start doing the calling.
  7. It’s important to have the coordinator do the work, so

    that the view controller remains inert.
  8. Which responsibilities do coordinators take over from the view controller?

    Primarily, navigation and model mutation. By model mutation I mean: - saving the user’s changes to the database - making a PUT or POST request to an API - anything that can destructively modify the user’s data
  9. We return protocol because it’s easy to test and, in

    this case, we follow the Open-Close principle.
  10. Router Router should do: - Handle all animation - Handle

    transitions - Handle routing (push, present, addChild, etc...) All logic related to handling animation and map should be remained in Router
  11. Ultimately, coordinators are just an organizational pattern. There’s no library

    you can use for coordinators because they’re so simple. There’s no pod you can install and nothing to subclass from.
  12. The main goal is to have unchained module-to-module responsibility and

    to build modules completely independently from each other. After this iteration we can easily reuse them in different flows.