title: Pass data in UIPageViewController between different swipe views
body: <p>I am working on a project with 3 views that are accessed by swiping.</p>
  
  <p>The following code implements the PageViewController I am using to handle the swiping motion: </p>
  
  <pre><code>import UIKit
  
  class PageViewController: UIPageViewController, UIPageViewControllerDelegate, UIPageViewControllerDataSource {
  
      lazy var orderedViewControllers : [UIViewController] = {
          return [self.newVC(viewController : "ClimaVC"),
              self.newVC(viewController : "WeatherVC"),
              self.newVC(viewController : "ClosetVC")]
      }()
  
      var myViewControllers = [UIViewController]()
  
      var currentIndex : Int = 0
  
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          // Do any additional setup after loading the view.
  
          self.dataSource = self
  
          setViewControllers([orderedViewControllers[1]],
                             direction: .forward, animated: true, completion: nil)
  
          self.delegate = self
      }
  
  
      func newVC(viewController : String) -&gt; UIViewController {
  
          return UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: viewController)
      }
  
      func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -&gt; UIViewController? {
  
          guard let viewControllerIndex = orderedViewControllers.index(of: viewController) else {
              return nil
          }
  
          let previousIndex = viewControllerIndex - 1;
  
          guard previousIndex &gt;= 0 else {
              // return orderedViewControllers.last
              //Return nil to avoid swiping forever.
              return nil
          }
  
          guard orderedViewControllers.count &gt; previousIndex else {
              return nil
          }
  
          currentIndex = previousIndex
  
          return orderedViewControllers[previousIndex]
      }
  
      func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -&gt; UIViewController? {
  
          guard let viewControllerIndex = orderedViewControllers.index(of: viewController) else {
              return nil
          }
  
          let nextIndex = viewControllerIndex + 1;
  
          guard orderedViewControllers.count != nextIndex else {
              //return orderedViewControllers.first
              //Return nil to avoid swiping forever.
              return nil
          }
  
          guard orderedViewControllers.count &gt; nextIndex else {
              return nil
          }
  
          return orderedViewControllers[nextIndex]
      }
  }
  </code></pre>
  
  <p>The main View Controller is <em>WeatherVC</em>. In this view, time data is retrieved and stored in an integer variable named <strong>timeOfDay</strong>. </p>
  
  <p>Depending on the value of <strong>timeOfDay</strong>, the background displayed will differ. While I was able to use this variable in <em>WeatherVC</em>, I need to pass this variable <strong>timeOfDay</strong> to the two other view controllers <em>ClimaVC</em> and <em>ClosetVC</em>. </p>
  
  <p>I tried setting up a delegate protocol but failed, explored using the different functions provided by UIPageViewControllerDelegate and it did not get me anywhere. </p>
  
  <p>I would really appreciate some help on this, </p>
  
  <p>Thank you very much!</p>