Swift 2:"Bool"不能转换为'BooleanLiteralConvertible'

Nik*_*hin 6 xcode ios uipageviewcontroller swift swift2

我创建了一个应用程序XCode 6.今天我下载了XCode 7,它已经更新了我的应用程序Swift 2.有很多错误,但现在只有一个我无法解决.我不知道为什么,但Xcode不喜欢任何Bool选项animated并显示此错误 -

'Bool'不能转换为'BooleanLiteralConvertible'

(如果你看一下这个函数本身,你会看到它完全Bool需要animated)

var startVC = self.viewControllerAtIndex(indexImage) as ContentViewController
var viewControllers = NSArray(object: startVC)

self.pageViewContorller.setViewControllers(viewControllers as [AnyObject], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)
    'Bool' is not convertible to 'BooleanLiteralConvertible'
Run Code Online (Sandbox Code Playgroud)

有谁知道,我该怎么解决?

谢谢.

vac*_*ama 12

Swift很困惑,并给你一个不正确的错误信息.问题是第一个参数是类型[UIViewController]?,所以以下应该工作:

self.pageViewContorller.setViewControllers(viewControllers as? [UIViewController], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

或者甚至更好,声明viewControllers为类型,[UIViewController]然后在调用中不需要转换:

let viewControllers:[UIViewController] = [startVC]
self.pageViewContorller.setViewControllers(viewControllers, direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)