Literal String vs. `String` in swift

ios, swift

Solution

My guess is that in the first example the compiler uses the call to `integerValue` as additional information to infer the type (choosing between NSString and a Swift String).

In the second example it probably defaults to a Swift String because it doesn't evaluate multiple lines.

Problem

Playing with swift I found this surprising: ``` "123".integerValue // <= returns 123 var x = "123" x.integerValue // <= Error: String does not have a member named integerValue ``` Can someone explain?

Original source