4
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
Fogmeister
  • 76,236
  • 42
  • 207
  • 306
Nat
  • 12,032
  • 9
  • 56
  • 103
  • 2
    I think the compiler is reporting a wrong error. Maybe try `let key: String! = "userTrackingMode"` and then use `key` instead of the literal. That could help the compiler to print the real error. – Sulthan Jul 04 '16 at 13:42
  • @Sulthan You were right. Post this please as an answer. – Nat Jul 04 '16 at 13:47

1 Answers1

13

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.

Sulthan
  • 128,090
  • 22
  • 218
  • 270