I have MainViewController
that is my UIPageViewController. Ther are 2 views FirstDataViewController
and SecondDataViewController
that i want to show.
I want to execute my request that updates items in MainViewControllre
and then pass it to my 2 child views.
getData
is my function that contains data from Request and then updates MainViewController's
items
extension MainViewController {
func getData() {
getBasicData() { [weak self] (basicModel) in
guard let strongSelf = self else { return }
strongSelf.getExperienceData() { [weak self] (experienceModel) in
guard let strongSelf = self else { return }
let items = RequestItems(basicData: basicModel,
experienceData: experienceModel)
strongSelf.updateItems(items: items)
}
}
}
}
MainViewController:
class MainViewController: UIPageViewController {
var items: RequestItems
let firstDataViewController: FirstDataViewController
let secondDataViewController: SecondDataViewController
let basicDataManager: APIManagerProtocol
let experienceDataManager: APIManagerProtocol
private(set) lazy var orderedViewControllers: [UIViewController] = {
return [self.firstDataViewController, self.secondDataViewController]
}()
convenience init() {
self.init(with: RequestItems())
}
init(with items: RequestItems) {
self.items = items
let apiManager = APIManager()
basicDataManager = apiManager.createBasicDataManager()
experienceDataManager = apiManager.createExperienceDataManager()
self.firstDataViewController = FirstDataViewController(with: items)
self.secondDataViewController = SecondDataViewController(with: items)
super.init(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
self.edgesForExtendedLayout = []
}
func updateItems(items: RequestItems) {
self.items = items
}
}
How to use getData()
function to update MainViewController items first and then pass data to child views? Or maybe there is just better option to do this?