Error: 'String' is not convertible to '

2019-07-11 05:06发布

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条回答
不美不萌又怎样
2楼-- · 2019-07-11 05:31

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.

查看更多
登录 后发表回答