我在 XCode 6
中创建了一个应用程序。今天我下载了 XCode 7
并将我的应用更新为 Swift 2
。有很多错误,但现在只有一个我无法解决。
我不知道为什么,但是 Xcode
不喜欢 animated
的任何 Bool
选项并显示此错误 -
'Bool' is not convertible to 'BooleanLiteralConvertible'
(如果你看一下函数本身,你会发现,它恰好采用了 animated
的 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], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)
或者甚至更好,将 viewControllers
声明为 [UIViewController]
类型,然后在调用中不需要转换:
let viewControllers:[UIViewController] = [startVC]
self.pageViewContorller.setViewControllers(viewControllers, direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)
关于ios - swift 2 : "Bool' is not convertible to 'BooleanLiteralConvertible' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31637106/