Eric Eric - 6 months ago 41
Swift Question

Swift 3.0 Cannot convert value of type ‘Int’ to expected argument type ‘Double’

I cannot figure out how to convert value of type

to expected argument type
in Swift 3.0 for
mph = kph * 0.6214
in the following code:

var mph : Double!
var kph : Float!

print("KPH MPH")


for kph in 60.stride(to: 130, by: 10) {
mph = kph * 0.6214
print("\(kph) \(mph)")

How do I program the
to produce the desired results?


Simply declare the initial value as literal Double (adding .0)

for kph in 60.0.stride(to: 130, by: 10) {

Then the compiler infers the type of the function as Double and converts the other literals implicitly.