 class MainPageViewController: UIPageViewController, PFLogInViewControllerDelegate, PFSignUpViewControllerDelegate, UIPageViewControllerDelegate, UIPageViewControllerDataSource {
     
     var posts: [Post]!
+    var index: Int!
     
     override func viewDidLoad() {
         super.viewDidLoad()

            postsQuery.whereKey("user", equalTo: PFUser.currentUser()!)
            postsQuery.findObjectsInBackgroundWithBlock {(objects:[PFObject]?, error: NSError?) -> Void in
                self.posts = objects as? [Post] ?? []
                for post in self.posts {
                    print(post)
                }

    
    func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
        print("previous")
        
        // None left, don't scroll.
        if self.index == 0 {
            return nil
        }
        
        self.index = self.index - 1
        let post: Post = self.posts![self.index!]
        let postViewController = PostViewController()
        postViewController.post = post
        return postViewController
    }
    
    func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
        print("next")
        
        // None left, don't scroll.
        if self.index == self.posts.count {
            return nil
        }
        
        self.index = self.index + 1
        let post: Post = self.posts![self.index!]
        let postViewController = PostViewController()
        postViewController.post = post
        return postViewController
    }

}
