ios - swift 2 : "Bool' is not convertible to 'BooleanLiteralConvertible'

标签 ios xcode swift uipageviewcontroller swift2

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

'Bool' is not convertible to 'BooleanLiteralConvertible'

(如果你看一下函数本身,你会发现,它恰好采用了 animatedBool)

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/

相关文章:

swift - 无法在模拟器 Xcode 6 中运行应用程序

ios - 我如何继承 AVPlayer?

ios - Xcode - 无法获取进程-1的任务

xcode - 类似 iPad Safari 的缩略图缩放 View

ios - CommonCrypto 不是为 arch armv7 iOS 构建的

ios - Swift 多项选择输入答案

ios - swift : setup a Pan Gesture left to right

ios - 尝试在 Swift 2.0 中解析 json 数据时出现错误?

ios - 电子签名集成使我的多页 pdf 变成单页

ios - 键盘超越日期选择器