Read More

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!

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close