title: how to auto scroll with timer in page view controller in swift 3?
body: <p>Hi  I just want to scroll pages in page view controller automatically with timer in swift 3 - so after I read similar questions I used this Extension code to auto scroll in page view controller But It Didn't worked for me </p>
  
  <p>here is the Extension Code </p>
  
  <pre><code>extension pageVC2 {
  func goToNextPage(animated: Bool = true, completion: ((Bool) -&gt; Void)? = nil) {
      if let currentViewController = viewControllers?[0] {
          if let nextPage = dataSource?.pageViewController(self, viewControllerAfter: currentViewController) {
              setViewControllers([nextPage], direction: .forward, animated: animated, completion: completion)
          }
      }
  }
  }
  </code></pre>
  
  <p>and then I tried Another answer so I used This code But I will get Error with ScrollView </p>
  
  <p>Here is the second way that I tried </p>
  
  <pre><code>func moveToNextPageTwoSecond (){
  
      let pageWidth:CGFloat = CGRectGetWidth(self.scrollView.frame)
      let maxWidth:CGFloat = pageWidth * 4
      let contentOffset:CGFloat = self.scrollView.contentOffset.x
  
      var slideToX = contentOffset + pageWidth
  
      if  contentOffset + pageWidth == maxWidth{
          slideToX = 0
      }
      self.scrollView.scrollRectToVisible(CGRectMake(slideToX, 0, pageWidth, CGRectGetHeight(self.scrollView.frame)), animated: true)
  }
      override func viewDidLoad() {
      super.viewDidLoad()
  
          Timer.scheduledTimer(timeInterval: 2, target: self, selector: #selector(pageVC2.moveToNextPageTwoSecond), userInfo: nil, repeats: true)
   }
  </code></pre>