UIPageViewController get second element of viewControllers array

I'm using a UIPageViewController to scroll between viewControllers. I have everything working with the swipe gesture, but I also have buttons within the toolbar (from a navigation controller) so the user can jump directly to a given view controller. I have six view controller in my array (orderedViewControllers). I can access the first view controller (code below) and the last view controller using .first and .last, but I can't work out how to access the other view controllers in my array. Using orderedViewControllers[1] doesn't work because that returns an Int, as what I need is to return a viewController. I'm probably missing something very obvious, but I can't work it out. Any help appreciated.


@IBAction func introScrollToPage1(_ sender: UIBarButtonItem) {
        if let firstViewController = orderedViewControllers.first {
            self.setViewControllers([firstViewController], direction: .reverse, animated: true, completion: nil)
            self.pageControl.currentPage = 0
        }
    }


Cheers

Grant.

Accepted Reply

I solved it by using:


let list = orderedViewControllers
let controller = list[1]
self.setViewControllers([controller], direction: .forward, animated: true, completion: nil)


Cheers

Grant

Replies

I solved it by using:


let list = orderedViewControllers
let controller = list[1]
self.setViewControllers([controller], direction: .forward, animated: true, completion: nil)


Cheers

Grant