I tried to execute a simple mathematical UIView diagram in Swift and tried the following line of code ...
var offset: CGFloat = (bounds.width / 2.0) - ((sortedSymptoms.count * bounds.height) / 2.0)
and received the following error from the compiler:
cannot invoke '-' with an argument list of type '(($T6), ($T17))' var offset: CGFloat = (bounds.width / 2.0) - ((sortedSymptoms.count * bounds.height) / 2.0) ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A compiler error is not so useful, but it seems that there is a type conflict between Double, Int and CGFloat. I managed to compile this line by sending some explicit creations of CGFloats, but I cannot believe that this is the right way to do this.
var offset: CGFloat = (bounds.width / CGFloat(2.0)) - ((CGFloat(sortedSymptoms.count) * bounds.height) / CGFloat(2.0))
What is the right way?
source share