Open rbsgn opened 8 years ago
Hey! and sorry for the many months it's taken to get back (Mail insists GitHub is spam!). It's correct there is only one reference to storyboardSegueHandler but this is all that's required to handle scenes with more than one segue. It's a good question because it would be important for this technique to work for example when you have multiple contained view controllers embedded in one view controller.
What this pattern does is effectively remove the significance of the segue and makes the destination the central object in the decision of what code to call.
The long lived single instance of storyboardSegueHandler is little more than a middleman that maintains any long lived context (e.g. dependancies you may want to pass around) but does nothing other than dispatches the work to a 'Visitor' instance that does the work of configuring the destination.
It creates a fresh instance of the Visitor for every segue. In the example 'StoryboardController' is the visitor and is extended via Protocol Extension with support for each ViewController by the file 'SceneDispatchTable' - this is done to group all the functionality for the Visitor pattern in one place.
It's a bit of a hard one to follow in terms of how all the bits knit together but in return you get a lot of flexibility.
I dig into your approach of working with segues and one question popped up in my mind: How to handle a scene with more than one segue? Currently
StoryboardManagedScene
has only onestoryboardSegueHandler
that is intended to handle one segue, right? What if scene has two segues?