swift - 错误 : 'String' is not convertible to 'String!'

标签 swift string reactive-cocoa

mapView.rac_valuesForKeyPath("userTrackingMode", observer: self).subscribeNextAs { 
// block handling

我收到错误消息 'String' is not convertible to 'String!'。有什么建议吗?

我曾经认为,String!String 相同,所以它是未包装的 String?...

  • Xcode 7.3.1
  • swift 2.2
  • ReactiveCocoa 4.1.0

最佳答案

我认为编译器报错了。

您可以使用

简化表达式
let key: String! = "userTrackingMode"

然后使用 key 而不是文字。

这将简化表达式并帮助编译器打印出真正的错误。

类型推断很复杂,当编译器找不到有效的类型组合时,它会向您显示错误。

关于swift - 错误 : 'String' is not convertible to 'String!' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38186121/

相关文章:

Swift/OS X - 删除应用程序标题栏并添加自定义关闭按钮

javascript - 在 javascript 中搜索对象数组中的重复字符串

ios - 设置间隔时 QueueScheduler 不触发

swift - 如何以编程方式使 NSSlider 垂直?

ios - 使用 "self"的未解析标识符

android - 布局看起来不同?

wpf - 关于 ViewModel 对简单状态的责任的 MVVM 设计选择

swift - 观察 UISwich 控件状态

ios - 在 Swift 中访问自定义 UITableViewCell UILabel 文本会引发错误

c++ - 将字符串对象与 C++ 中的字符串文字进行比较 : why no compile errors?