How to use CGFloat in Swift?

var posinonY:Float = Float(y) + Float(pipeDown.size.height) + Float(verticalPipeGap) pipeDown.position = CGPointMake(0.0, Float(posinonY)) 

I get this error:

"NSNumber" is not a subtype of "CGFloat"

Why?




Edit:

CGFLoat needs a double type

 pipeDown.position = CGPointMake(0.0, Double(posinonY)) 

this is normal.

+16
swift
Jun 03 '14 at 7:55
source share
2 answers

Use CGFloat(number) instead of Float(number)

 pipeDown.position = CGPointMake(0.0, CGFloat(posinonY)) 
+36
Jun 03 '14 at 8:01
source share

Since CGFloat not a 32-bit Double , it becomes difficult to use CGGeometry and frameworks such as CoreGraphics or SpriteKit. This library simplifies things a bit and hopefully Apple will take care of this soon.

I wrote this to help https://github.com/seivan/ScalarArithmetic

But if you want to just make it work without dependencies, use var myFloat:CGFloat and make sure that you produce any Double (numbers that are output by type) on CGFloat 2.0 is considered double and will not play along with CG-Structs at 32 bit.

+7
Jul 07 '14 at 12:06 on
source share



All Articles