Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where and how to perform segues in VIPER architecture?

As a beginner, I used to perform segues in ViewControllers. Moreover, Apple encourages such approach, because UIViewController has methods performSegue and prepareForSegue.

But learning VIPER, I read that Router is responsible for transitions between scenes. And the second thing is that according to VIPER flowcharts like this:

enter image description here

Router mustn't be tied with View.

I absolutely don't want to refuse from using segues, because it is extremely powerful and allows me to easily transfer data between ViewControllers.

So, how should I perform transitions between ViewControllers?

like image 321
Gleb Kalachev Avatar asked Oct 20 '25 12:10

Gleb Kalachev


2 Answers

In pure VIPER all transitions should be performed in Router. So you would not be able to use segues if you'll choose to implement VIPER

like image 167
Andrey Volobuev Avatar answered Oct 23 '25 02:10

Andrey Volobuev


Personally I prefer using Storyboard ID rather than segues. For example :
1. Put a relevant storyboard ID for your view. image link.
2. Then you can access that view like : let loginVC = UIStoryboard(name: "Main", bundle:nil).instantiateViewController(withIdentifier: "Login")
3. You can pass data with it like: loginVC.type = 0
4. You can access it whenever you want like: navigationController?.pushViewController(loginVC, animated: true)

like image 21
ReMeDy Avatar answered Oct 23 '25 04:10

ReMeDy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!