Type conversion for NSRect parameters

Am I doing something wrong, or does Swift have to be written with constant conversions? For example, I want to define a NSRect

circle for drawing, and I have already determined NSPoint

which will be its center, also I have a radius of the type Float

that will determine the width and height, but this should be multiplied by the scale Int

before, so I do it like this:

let objectRect = NSRect(x: center.x - radius*scale ...

      

I am getting a warning that I cannot propagate Int

to Float

. So now it looks like this:

let objectRect = NSRect(x: center.x - radius*Float(scale) ...

      

Now that part is fine, but another warning says what Float

cannot be subtracted from CGFloat

. Another conversion:

let objectRect = NSRect(x: Float(center.x) - radius*Float(scale) ...

      

Looks awful already, but at the top of the sticking out last warning says that NSRect does not accept Float, so I need to convert it to Double.

+3


source to share


1 answer


Do this only once. And as below, use CGFloat

right away:

let objectRect = NSRect(x: CGFloat(center.x) - radius* CGFloat(scale) ...

      



Based on scripting languages, a system like Swift can be annoying. However, you are used to it.

+1


source







All Articles