Eric Eric - 1 year ago 151
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download