Correct way to update UIPageViewController after an API request

I have a problem when I try to do a GET request with Alamofire. In my viewDidLoad method. I already checked that my request works and my arrays are populated but when I run the code I get a fatal error: Index out of range because when I called getViewControllerAtIndex method the arrays are empty at that moment.
How can I do if I want to create my UIPageViewController with the data coming from my API.
This my code in ViewController.swift

// Use this method to return to previous view. In this I have put a condition such that if it is first view then return nil otherwise return ViewController.
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {

// Use this method to return next view. In this I have put a condition such that if it is last view then return nil otherwise return ViewController.
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {

Needs to be called in the alamofire callback not outside of that scope. The array you are populating from (arrPageTitle) would be empty at the point you are calling setViewControllerAtIndex and you are accessing values in the array with index giving you the out of bounds error.