UIPageViewController setViewControllers in Swift

I'm having trouble with an error while implementing a UIPageViewController in Swift.


There is my code:

    var pageViewController: UIPageViewController? = nil
    let pageTitles = ["One", "Two", "Three"]
   
    override func viewDidLoad() {
        super.viewDidLoad()
       
        pageViewController = self.storyboard!.instantiateViewControllerWithIdentifier("PageViewController") as? UIPageViewController
        pageViewController!.dataSource = self;
   
        let startingViewController = viewControllerAtIndex(0);
        let viewControllers = [startingViewController]
       
        pageViewController!.setViewControllers(viewControllers, direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
    }


At line 14 I get this error:

Cannot invoke 'setViewControllers' with an argoument list of type '([PageContentViewController?], direction UIPageViewControllerNavigationDirection, animated: Bool, completion: nil)'


Well, I think this is related to unwrap the property I declared at line 2 but I don't know how to do it

Can someone help me?

Thank you

It seems likely that you are getting this error because viewControllerAtIndex in line 10 returns an optional value, thus viewControllers in line 11 is an array of optional values, and setViewControllers in line 13 takes an array of non-optional values, not an array of optional values. Probably the best behavior for you would be to make line 10 "let starting ViewController = viewControllerAtIndex(0)!". After doing that, you can option-click over "startingViewController" and "viewControllers" to ensure their data types are right.

UIPageViewController setViewControllers in Swift
 
 
Q