Cannot convert value of type '[Double]' to expected argument type 'Double'

I can't fix this error.

Cannot convert value of type '[Double]' to expected argument type 'Double'


let someValue = Double(SomeValue  /  SomeValue)  // error is here

Answered by H957169 in 691239022

Thank you very much, I corrected the code and the error disappeared.

@H957169 some friendly tips:

  • Please remember always to respond, when people try to help you.
  • Include enough information in your question to allow people to understand your problem.
  • When one of your questions is answered, remember to mark the question as answered.
  • Then the forum will work as intended, and people will be more likely to help you in future.

You should show more. We need to know what SomeValue are.

Please show the real code.

But probably:

  • You have defined and Array of Double
  • Then you try to give it a value of Double, not array.

"someValue" is expecting a type of "Double"

So "SomeValue" and the other "SomeValue" must both be of type "Double"
The error message suggests that one (or both) of them is not.

If you include more code details, it will be possible to say exactly where the error lies.

You should better read the things robnotyou has written for you and for all the readers.

Thank you, I know how to solve.

Sorry, but unfortunately the conversion of Int values to Double values failed. How to convert the values in the Int array into Double values so that the two values are divided by each other ?


  let NewTime = [newHour, newMinute, newSeconds]

        let NewHour = newHour

        let NewMinute = newMinute

        let NewSeconds = newSeconds

        let NewDistance = newDistance

        let NewMeter = newMeters

        let NewKilometer = newKilometers

        let NewMiles = newMiles

        let NewYards = newYards

        let NewPace = [perMeter, perKilometer, perMile, perYard]

        

        

        let calculatePace = (NewTime / NewDistance)

        

        return calculatePace

    }

}

"NewTime" is an array (of something - you don't say what.
"NewDistance" is... what... you don't say.

Then you have:

 let calculatePace = (NewTime / NewDistance)

...where you divide an Array by something.

That doesn't make sense.

Please show the complete code.

What is the use to redefine each value, such as

let NewHour = newHour

instead of using only newHour ?

Note also that Swift var should begin with lowercase.

If the problem is you need Double, maybe you have to:

        let calculatePace = Double(NewTime[0]*3600 + NewTime[1]*60 + NewTime[2]) / Double(3600 * NewDistance)

or

        let calculatePace = Double(newHour*3600 + newMinute*60 + newSeconds) / Double(3600 * NewDistance)

This will give hour/km, is it what you want ?

If you want km/h, it should be the reverse:

        let calculatePace = Double(3600 * NewDistance) / Double(NewTime[0]*3600 + NewTime[1]*60 + NewTime[2])

or

        let calculatePace = Double(3600 * NewDistance) / Double(newHour*3600 + newMinute*60 + newSeconds)

But once again, tell what you expect, what you get, where is eventual crash and show comprehensive code. And don't forget to close the thread on the correct answer once you got it.

Accepted Answer

Thank you very much, I corrected the code and the error disappeared.

Cannot convert value of type '[Double]' to expected argument type 'Double'
 
 
Q