I have the following setup :
Launch VC performs an asynchronous API request in a closure
dataGatheringClosure
The
dataGatheringClosure
closure's completion handler passes the result to VC1 via delegation using protocol methodsetData
.Within
setData
, VC1 passes the result to VC2 using the following code:if let vc2 = self.tabBarController?.viewControllers?[1] as? VC2Controller { vc2.data = result }
I'm able to transfer data from the Launch VC to VC2, but now I need to refresh the data by performing the dataGatheringClosure
in Launch VC.
My question is: How do I access Launch VC's methods from VC2? And is this approach sound?
As a workaround, I copied the dataGatheringClosure
closure code inside TabBar VC and had VC 2 call its self.tabBarController.dataGatheringClosure
method. However, it is duplicative, and also I don't know if it's best practice to execute heavy API requests within a TabBarController
.