"The Swift Programming Language" contains the following sample code:
let label = "The width is "
let width = 94
let widthLabel = label + String(width)
When I changed width
implicitly to Double:
let width = 94.4
a compiler error is created for the line let widthLabel = label + String(width)
:
Cannot invoke '+' with an argument list of type (String, String)
While I can convert the Double
var to String
by calling width.description
, I want to know:
- Why
String(Integer)
works butString(Double)
doesn't? - Is there any difference between calling
String(var)
andvar.description
on a numerical type (Integer, Float, Double, etc)?