Better way to move from one View Controller to another View Controller


In this blog, I am discussing how we can reduce a bunch of repetition code.

In old code structure, we use different storyboard and each storyboard contains multiple view controllers.

So moving from one controller to another firstly we have to create an instance of storyboards and create the reference of view controller from that we can push or present view controller over the current view controller and that same code we have to write in each class where we are moving from one controller to the another.

Here is the example of repetition which we usually used to write:-

As we all know in swift, we say enum class first last so with the use enum we create a number of case equal to the number of storyboards our project contains with their raw value(which refers their actual name):-

For moving one controller we need these things one is storyboard instance and another is view controller reference.

From storyboard raw value we can get storyboard instance and from View controller itself, we can get view controller’s identifier from them we can create there reference.  so we can use generics to implement this feature in the enum:

How to use them:-

I hope from this, it will make you more comfortable dealing with different storyboards and view controllers. Thanks for tuning in once again!

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


  • Ashish Nimbria
    Thank you. This is the better approach to manage storyboards. Excellent work.
    • jitendra kumar (Moderator)
      Your welcome
  • css.php

    All communication is done through a ticket system. I appreciate the regular almost daily updates of what is being worked on, and communicating changes or updates is easy through this system. Mobikul's response timeframe is quick.

    Josh Arnold

    Josh Arnold

    Owner, Shop ATV Escape

    Talk to Sales


    Live Chat
    Start a Project

      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home