Why does a simple thing like Rounding is so complicated in Swift?
This is an extension on Double.
I tried
round(self - 273.15)
and got the same error.
Also tried:
(self - 273.14).round()
The round
that you are trying to use is a mutating member of the Double
type. Try this instead:
func toCelsius() -> Double {
return (self - 273.15).rounded()
}
To clarify, a mutating
member means that it changes the value itself (and in this case, returns Void
). This means that it cannot be called on constants (or the results of computations, as in your case).
The function I am using, rounded()
, is not a mutating member, and returns a Double
— exactly what you want.
The answer is actually offtopic, nevertheless there is a simpler solution for this particular case.
According to your previous question it seems that you are dealing with the openweathermap API.
If you add
units=metric
to the URL query you get all degrees in Celsius.