When we are creating segues through the use of Storyboard we generally have a similar pattern.
We can use a constant to make the code a little better.
This is better but we can use the power of extensions to make it better and more concrete.
SegueHandler protocol is implemented by all the view controllers who are interested in taking part in the segue. Now, the view controller can conform to the segue and provide the SegueIdentifier definition as shown below:
The above technique allows the view controller to be more explicit about the use of segues and the enum defines all the possible segues that can originate from the view controller.
If you like this post then you might be interested in checking out my course “A Complete Guide to Lean Controllers in iOS”. The course covers many useful architecture patterns to build better iOS applications. Receive a 74% discount, click on the following link:
- The above technique was demonstrated in one of the WWDC sessions.