title: Page Indicator out of sync swift
body: <p>I have the following <code>PageViewController</code> class : </p>
  
  <pre><code>class ProjectorPageViewController : UIPageViewController, UIPageViewControllerDataSource {
  
  var randUsed : [String]?
  
  var pageViewMatches : [SingleMatch]? {
      didSet {
         //irrelevant code
  
          }
          let initialcontroller = viewControlerAtIndex(0)
  
          let viewControllers = [initialcontroller!]
          setViewControllers(viewControllers, direction: .Forward, animated: true, completion: nil)
      }
  }
  
  
  
  override func viewDidLoad() {
      super.viewDidLoad()
      dataSource = self
      let pageControl = UIPageControl.appearance()
      pageControl.currentPageIndicatorTintColor = UIColor.whiteColor()
      pageControl.pageIndicatorTintColor = UIColor(red: (69/255.0), green: (209/255.0), blue: (153/255.0), alpha: 1.0)
  }
  
  
  func viewControlerAtIndex(index : Int) -&gt; PageViewContentViewController? {
  
      if (self.pageUsers!.count == 0 || index &gt;= self.pageUsers!.count) {
          return nil
      }
  
      let controller = PageViewContentViewController()
      controller.location = pageLocations![index]
      controller.image_name = pageImages![index]
      controller.user_name = pageUsers![index]
      controller.pageIndex = index
      return controller
  
  }
  
  
  func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -&gt; UIViewController? {
      let curr_index = (viewController as! PageViewContentViewController).pageIndex
      print ("attempting after with index : " + String(curr_index))
  
      if (curr_index! &lt; pageViewMatches!.count - 1) {
          return viewControlerAtIndex(curr_index! + 1)        }
      else {
          return nil
      }
  }
  
  func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -&gt; UIViewController? {
      let curr_index = (viewController as! PageViewContentViewController).pageIndex
      print ("attempting before with index : " + String(curr_index))
      if (curr_index! &gt; 0 ) {
          return viewControlerAtIndex(curr_index! - 1)
      }
      else {
          return nil
      }
  
  
  }
  
  
  
  func presentationCountForPageViewController(pageViewController: UIPageViewController) -&gt; Int {
      if let matches = pageViewMatches {
  
      return matches.count
  }
      else {
          return 0
      }
  }
  
  func presentationIndexForPageViewController(pageViewController: UIPageViewController) -&gt; Int {
      return pageViewController.viewControllers!.indexOf((pageViewController.viewControllers?.first)!)!
  }
  
  
  
  }
  </code></pre>
  
  <p>The problem is that if I swipe fast enough between the pages, the page indicator becomes out of sync, and points to the wrong page. If I swipe at a moderate pace this doesn't occur. I have seen a similar post which said the solution was to implement the <code>presentationIndexForPageViewController</code> method, however translating this from Objective-C (unless I made a mistake in translation) did not solve the problem. Here is the post I am referring to : <a href="https://stackoverflow.com/questions/21406833/uipageviewcontroller-setviewcontrollers-uipagecontrol-not-showing-right-current?lq=1">UIPageViewController setViewControllers, UIPageControl not showing right current number</a></p>