title: Swift 2 Cannot convert value of type '[AnyObject]' to expected argument type '[UIViewController]?'
body: <p>I am working on a project in Swift and I just automatically converted my code from <code>Swift 1</code> to <code>Swift 2</code>. However I am getting the error:</p>
  
  <blockquote>
    <p>Cannot convert value of type '[AnyObject]' to expected argument type
    '[UIViewController]?'</p>
  </blockquote>
  
  <p>In the following piece of code:</p>
  
  <pre><code>self.pageViewController.setViewControllers(viewControllers as [AnyObject], direction: .Forward, animated: true, completion: nil)
  </code></pre>
  
  <p>I originally thought that the problem would be solved if I said <code>as!</code> rather than <code>as</code> but when I did this I received the following message:</p>
  
  <blockquote>
    <p>Forced cast from 'NSArray' to '[AnyObject]' always succeeds; did you
    mean to use 'as'?</p>
  </blockquote>
  
  <p>Followed by this error:</p>
  
  <blockquote>
    <p>Cannot convert value of type '[AnyObject]' to expected argument type
    '[UIViewController]?'</p>
  </blockquote>
  
  <p>Here is my entire code for context: </p>
  
  <pre><code>    override func viewDidLoad()
  {
      super.viewDidLoad()
  
      self.pageTitles = NSArray(objects: "", "", "")
      self.pageImages = NSArray(objects: "page1", "page2", "page3")
  
      self.pageViewController = self.storyboard?.instantiateViewControllerWithIdentifier("PageViewController") as! UIPageViewController
      self.pageViewController.dataSource = self
  
      var startVC = self.viewControllerAtIndex(0) as ContentViewController
      var viewControllers = NSArray(object: startVC)
  
      self.pageViewController.setViewControllers(viewControllers as! [AnyObject], direction: .Forward, animated: true, completion: nil)
  
      self.pageViewController.view.frame = CGRectMake(0, 30, self.view.frame.width, self.view.frame.size.height - 60)
  
      self.addChildViewController(self.pageViewController)
      self.view.addSubview(self.pageViewController.view)
      self.pageViewController.didMoveToParentViewController(self)
  
      // Below is for advertisements
  
      self.canDisplayBannerAds = true
      self.addBannerView?.delegate = self
      self.addBannerView?.hidden = true
  
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  @IBAction func restartAction(sender: AnyObject)
  {
      var startVC = self.viewControllerAtIndex(0) as ContentViewController
      var viewControllers = NSArray(object: startVC)
  
      self.pageViewController.setViewControllers(viewControllers as! [AnyObject], direction: .Forward, animated: true, completion: nil)
  }
  
  func viewControllerAtIndex(index: Int) -&gt; ContentViewController
  {
      if ((self.pageTitles.count == 0) || (index &gt;= self.pageTitles.count)) {
          return ContentViewController()
      }
  
      let vc: ContentViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ContentViewController") as! ContentViewController
  
      vc.imageFile = self.pageImages[index] as! String
      vc.titleText = self.pageTitles[index] as! String
      vc.pageIndex = index
  
      return vc
  
  
  }
  </code></pre>
  
  <p>Obviously I am very confused by this error, any help would be appreciated. </p>
  
  <p>Thank you, 
  Ahad Sheriff</p>