So long, Flow Controller

So long, Flow Controller

Presented at CocoaHeads Montreal on September 26th, 2019.

732de78cba7ebf62ccb9cf3ea08d618b?s=128

Olivier Collet

September 26, 2019
Tweet

Transcript

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

  2. The Story

  3. December 2012
 Seb Morel presents at CocoaHeads Montreal:
 “How to

    Avoid the Flying Spaghetti Code Monster!”
  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
  5. January 2014
 CocoaHeads Paris:
 “Flow Controller”

  6. February 2014
 Blog post:
 “Give Your App a Brain With

    a Flow Controller”
  7. January 2015
 Soroush Khanlou writes a blog post:
 “The Coordinator”

  8. February 2016
 CocoaHeads Montreal:
 “Flow Controller - Revisited”

  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
  10. Flow Controller

  11. Flow Controller ☠ DEAD

  12. Best code is no code.

  13. Inherits from UIResponder with a reference to a root UIViewController

    Inherits from UIViewController UINavigationController, UITabBarController, or custom container view controller
  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
  15. Event + EventHandler

  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 { }
  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? }
  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

  19. Annie Spratt

  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
  21. Olivier Collet
 @ocollet ✌