Based on my answer here , here is the Swift version. Please note that this was converted from Objective-C to Swift using an online converter (since I am not on my development computer and usually do not work in Swift), with some added skills to get the right weak link. Feel free to point out any errors in the implementation.
pageViewController.setViewControllers( viewControllers, direction: UIPageViewControllerNavigationDirectionForward, animated: true, completion: { [weak pageViewController] (finished: Bool) in if finished { dispatch_async(dispatch_get_main_queue(), { pageViewController.setViewControllers( viewControllers, direction: UIPageViewControllerNavigationDirectionForward, animated: false, completion: nil ) }) } })
The trick with [weak ...] is called the "Capture List" and is well covered in this matter , as well as official documents , the section "Defining the Capture List".
(The intention, if you did not track this, is that we do not want our closure to have a strong link to the pageViewController and thus prevent ARC from freeing it if it is no longer needed. Therefore, we mark this variable as weak link, and if closing is the last thing left with a link to pageViewController , sayonara).
Another point: I did not pay attention to the aspect of options, so the developer is caveat.
EDIT:
Looking at your code, it doesn't seem like my answer is what you want. The problem is that the addresses of my answer programmatically configure the view controller, but you're talking about scrolling.
I assume that you did not implement all the delegate methods - I only see viewControllerAtIndex . You do not need to do viewControllerBeforeViewController and viewControllerAfterViewController for the item to work correctly? (Sorry, it's been a while since I was in this class.) A quick look at this tutorial makes me think so ...
In any case, he understands that the wrong tree is barking. Please check this and maybe clarify your question, show more code, etc.