Andrej Malyhin
Aug 25, 2017 · 1 min read

Hi Renato!

This question is really about modules communication. Let’s say you are in Create Profile module and after all fields are filled you are presenting User Profile module. Somehow you need to pass data (username, profile picture, email etc.) to another module. UIKit is build in a way that you are creating new UIViewController inside another one (from Storyboard, nib or purely from code) then setting all the data directly to it by using properties. In our case it will be

profileViewController.username= “john doe”profileViewController.profilePicture = UIImage(“https://blahblah”) //etc.

and then presenting it using present(controller:) method. VIPER sees View (UIViewController) as a passive object which means it does nothing navigation or configuration related — that’s basically the whole point of VIPER’s separation of responsibilities! Communication is straightforward here: Interactor gets “raw” data and applies business logic to it -> then Presenter gets the result and transforms it into a View-friendly objects -> View displays it. Interactor->Presenter->View (in case when user responds in the View (ex. by pressing button) View->Interactor->Presneter->View). So chain Interactor->Presenter->View is like circle of life in The Lion King.

It feels natural to pass data to Interactor directly so circle of life will not be broken. If you pass data directly to Presenter you’ll need to move some business logic inside of it which breaks Single Responsibility principle.

Hope it helps!

)

    Andrej Malyhin

    Written by

    iOS developer at Flo. @ankoma22

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade