ios - Xcode 7.2.1 Swift 2.1.1 无法将类型 'Dictionary<_,_>' 的值分配给类型 'Dictionary'

标签 ios xcode swift dictionary

我将 Xcode 更新到 7.2.1,在编译时我从不同的文件中多次收到以下错误。

即使我注释掉我在该文件中使用的词典,我仍然会遇到错误。我不明白为什么它不给我错误行。

enter image description here 我在这里声明和使用字典的示例:

  var viewControllersCache = [String: UIViewController]()
  ...
  viewControllersCache["notifications"] = notificationsContainer

我之前在使用以前版本的 xcode/swift 时没有遇到过编译问题。这与build设置有关,还是我错过了有关如何声明空字典/为它们赋值的内容。

感谢任何提示!

最佳答案

终于找到了。看起来像一个错误。

https://forums.developer.apple.com/thread/20531

解决方案是显式声明字典或数组,例如

 var viewControllersCache:Dictionary<String,UINavigationController> = Dictionary<String,UINavigationController>()

所以检查一下你的代码,看看哪里没有这样做。

希望这对某人有帮助。

关于ios - Xcode 7.2.1 Swift 2.1.1 无法将类型 'Dictionary<_,_>' 的值分配给类型 'Dictionary',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35507756/

相关文章:

ios - JSONModel 错误的属性协议(protocol)声明?

ios - 如何制作带有完成按钮的 UIPickerView?

ios - 如何使用 URLSession (Swift 4.2) 触发两 (2) 个 HTTP POST 请求?

xcode - 如何找到重复符号的位置

android - 将 mp3 文件从 Kiosk 直接传输到智能手机

ios - 如何根据 segue 执行操作

ios 在数据加载和隐藏原型(prototype)单元格时触发 TableView 中的事件指示器

ios - 手动和非自适应手动转场

ios - 使用来自另一个 View Controller 的 setter getter

ios - 删除 iOS 中的 HTML url 标签