I am using VIPER architecture in iOS swift. I have 2 viewcontrollers, let's say A
and B
. At first I'm going from A
to B
, performing some tasks and coming back from B
to A
. With MVC or MVVM, we can create protocols and transfer data from B
to A
. But for VIPER, i am confused. Here's my VIPER code B, while Back button is tapped:
View:
@IBAction func backButtonTapped(_ sender: UIButton) {
presenter?.goBack()
}
Presenter:
func goBack() {
router.back()
}
Router:
func back() {
viewController?.navigationController?.popViewController(animated: true)
//here I want to send data back to previous viewcontroller
}
I have tried creating one method in the Router of previous controller and sending the data through that method but it is not working as router doesn't have any instance of presenter or anything else, except view.