ios – Swift 2:“Bool”不能转换为’BooleanLiteralConvertible’

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

‘Bool’ is not convertible to ‘BooleanLiteralConvertible’

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

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'

有谁知道,我该怎么解决

谢谢.

解决方法

Swift很困惑,并给你一个不正确的错误信息.问题是第一个参数的类型为[UIViewController] ?,因此以下内容应该有效:
self.pageViewContorller.setViewControllers(viewControllers as? [UIViewController],completion: nil)

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

let viewControllers:[UIViewController] = [startVC]
self.pageViewContorller.setViewControllers(viewControllers,completion: nil)

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...