$30 off During Our Annual Pro Sale. View Details »

So long, Flow Controller

So long, Flow Controller

Presented at CocoaHeads Montreal on September 26th, 2019.

Olivier Collet

September 26, 2019
Tweet

More Decks by Olivier Collet

Other Decks in Programming

Transcript

  1. So long, Flow Controller
    Olivier Collet. CocoaHeads Montreal. 26.09.2019

    View Slide

  2. The Story

    View Slide

  3. December 2012

    Seb Morel presents at CocoaHeads Montreal:

    “How to Avoid the Flying Spaghetti Code Monster!”

    View Slide

  4. Flow Manager
    MVC
    Intent
    1. Get Model
    2. Setup Flow
    Dependent
    Elements
    3. Presents
    MVC
    Intent
    1. Get Model
    2. Setup Flow
    Dependent
    Elements
    3. Presents
    MVC
    Intent
    1. Get Model
    2. Setup Flow
    Dependent
    Elements
    3. Presents
    MVC
    Intent
    1. Get Model
    2. Setup Flow
    Dependent
    Elements
    3. Presents
    MVC
    Intent
    1. Get Model
    2. Setup Flow
    Dependent
    Elements
    3. Presents

    View Slide

  5. January 2014

    CocoaHeads Paris:

    “Flow Controller”

    View Slide

  6. February 2014

    Blog post:

    “Give Your App a Brain With a Flow Controller”

    View Slide

  7. January 2015

    Soroush Khanlou writes a blog post:

    “The Coordinator”

    View Slide

  8. February 2016

    CocoaHeads Montreal:

    “Flow Controller - Revisited”

    View Slide

  9. Flow Controller
    1. Keep the application’s state
    2. Manage the logic between view controllers
    3. Orchestrate the view controllers
    4. Prevent view controller dependencies
    5. Handle a portion of the application

    View Slide

  10. Flow Controller

    View Slide

  11. Flow Controller

    DEAD

    View Slide

  12. Best code is no code.

    View Slide

  13. Inherits from UIResponder
    with a reference to a root UIViewController
    Inherits from UIViewController
    UINavigationController, UITabBarController, or custom container view controller

    View Slide

  14. View controllers report via delegate
    with lots of delegate protocols in a complex view controller hierarchy
    View controllers report via the responder chain
    low key introducing the Event and EventHandler protocols

    View Slide

  15. Event + EventHandler

    View Slide

  16. Event

    protocol
    • Similar to Error

    Can be used as an enum with associated values 

    or as a struct with properties
    • Passed along the responder chain


    protocol Event {
    }

    View Slide

  17. EventHandler

    protocol
    • Implement to receive Events
    • Specifies the event that can keep being propagated

    down the responder chain or no event to propagate
    protocol EventHandler: AnyObject {
    func handleEvent(_ event: Event) -> Event?
    }

    View Slide

  18. UIResponder

    extension
    • func postEvent(_ event: Event)

    propagates the event up the responder chain
    • var eventHandler: EventHandler?

    can be used to hook an object that is not part of the responder chain


    View Slide

  19. Annie Spratt

    View Slide

  20. References
    • https://github.com/smorel/CocoaHeads-Avoiding-Spaghetti-Code/
    blob/master/cocoaheads%20-
    %20How%20to%20avoid%20the%20spaghetti%20code%20Monster.pd
    f
    • https://speakerdeck.com/ocollet/flow-controller-give-your-app-a-brain
    • https://ocollet.com/2014/02/06/flow-controller/
    • http://khanlou.com/2015/01/the-coordinator/
    • https://speakerdeck.com/ocollet/flow-controller-revisited
    • https://gist.github.com/ocollet/719216edad74a5135470cf508bf50277

    View Slide

  21. Olivier Collet

    @ocollet

    View Slide