【问题标题】:xcode 8 convert project to swift 3 - DBAlertController errorsxcode 8 将项目转换为 swift 3 - DBAlertController 错误
【发布时间】:2017-03-17 09:40:52
【问题描述】:

我正在尝试使用 xCode 7.4 转换内置于 swift 2.2 的应用程序。我现在正在使用 xCode 8.1 并将所有 pod 更新到最新版本。接下来,我将所有代码转换为 swift 3。除了 DBAlertController 框架出现 6 个编译器错误外,一切顺利。

在查看 github 页面时,似乎 DBAlertController 不支持 swift 3。我对 xCode/swift 开发非常陌生,所以不确定这里发生了什么。我最初没有在我的 Podfile 中设置版本,它安装了 0.2.6 版本。在 github 页面上看到此内容后,我将版本设置为 0.3.0,但在运行 pod install 时仍然出现编译器错误和以下错误。我的 cocoapods 版本是 1.2.0.beta.1。

任何关于修复或更换的想法都非常感谢。

[!] There are duplicate dependencies on `DBAlertController` in `Podfile`:

- DBAlertController (~> 0.3.0)
- DBAlertController

【问题讨论】:

    标签: ios xcode cocoa-touch swift3


    【解决方案1】:

    您可以将您的代码转换为Swift 2.3

    另外,您可以简单地显示警报,而不是使用DBAlertController。在Swift 3.0 中,您可以将警报显示为:

    let alertController: UIAlertController = UIApplication.shared.keyWindow?.rootViewController?.present(alertController, animated: true, completion: nil)
    

    或者你可以这样做:

    let alertController = UIAlertController(title: "title", message: "message", preferredStyle: .Alert)
    //...
    var rootViewController = UIApplication.shared.keyWindow?.rootViewController
    if let navigationController = rootViewController as? UINavigationController {
        rootViewController = navigationController.viewControllers.first
    }
    if let tabBarController = rootViewController as? UITabBarController {
        rootViewController = tabBarController.selectedViewController
    }
    rootViewController?.present(alertController, animated: true, completion: nil)
    

    查看stackoverflow's post 了解详情

    【讨论】:

      猜你喜欢
      • 2017-02-03
      • 2017-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多