Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

The Story

Slide 3

Slide 3 text

December 2012
 Seb Morel presents at CocoaHeads Montreal:
 “How to Avoid the Flying Spaghetti Code Monster!”

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

January 2014
 CocoaHeads Paris:
 “Flow Controller”

Slide 6

Slide 6 text

February 2014
 Blog post:
 “Give Your App a Brain With a Flow Controller”

Slide 7

Slide 7 text

January 2015
 Soroush Khanlou writes a blog post:
 “The Coordinator”

Slide 8

Slide 8 text

February 2016
 CocoaHeads Montreal:
 “Flow Controller - Revisited”

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

Flow Controller

Slide 11

Slide 11 text

Flow Controller ☠ DEAD

Slide 12

Slide 12 text

Best code is no code.

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

Event + EventHandler

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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


Slide 19

Slide 19 text

Annie Spratt

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

Olivier Collet
 @ocollet ✌