I learn to use the UIPageViewController in swift from this tutorial In the main View Controller:
// MARK: - Variables private var pageViewController: UIPageViewController? // MARK: - View Lifecycle override func viewDidLoad() { super.viewDidLoad() createPageViewController() setupPageControl() } private func createPageViewController() { let pageController = self.storyboard!.instantiateViewControllerWithIdentifier("PageController") as! UIPageViewController pageController.dataSource = self if contentImages.count > 0 { let firstController = getItemController(0)! let startingViewControllers: NSArray = [firstController] pageController.setViewControllers(startingViewControllers as! [PageItemController], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil) } pageViewController = pageController addChildViewController(pageViewController!) self.view.addSubview(pageViewController!.view) pageViewController!.didMoveToParentViewController(self) }
Can anyone explain for me, why we don't assign the pageViewController at the beginning like:
pageViewController = self.storyboard!.instantiateViewControllerWithIdentifier("PageController") as! UIPageViewController
Why do we need to assign the value to the "let" variable and then assign the "let" variable to the "var" variable?
Why do we make the thing complicated? :)
self.storyboard
is probably not immediately available (before viewDidLoad). – Thilo