Error: 'String' is not convertible to 'String!'

纵饮孤独 提交于 2019-12-12 18:24:51

问题


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

I get an error 'String' is not convertible to 'String!'. Any suggestions what this may mean?

I used to think, that String! is same as String, so it is unwrapped String?...

  • Xcode 7.3.1
  • Swift 2.2
  • ReactiveCocoa 4.1.0

回答1:


I think the compiler is reporting a wrong error.

You can simplify the expression using

let key: String! = "userTrackingMode"

and then use key instead of the literal.

That will simplify the expression and will help the compiler to print the real error.

Type inferring is complicated and when the compiler doesn't find a valid type combination, it can show you a wrong error.



来源:https://stackoverflow.com/questions/38186121/error-string-is-not-convertible-to-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!