user1671097
user1671097

Reputation:

Conversion Type Error CGPoint to CGFloat in Swift

   var _deltaTime = NSTimeInterval()

   var _pointsPerScndSpeed = Double()

   var bgVelocity: CGPoint = CGPointMake(_pointsPerScndSpeed, 0.0)

      //Cannot convert the expression's to type 'CGFloat'

     var amToMove:CGPoint = CGPointMake(bgVelocity.x * _deltaTime, bgVelocity.y * _deltaTime)

       //Could not find an overload for '*' that accepts the supplied Arguments

Upvotes: 0

Views: 2099

Answers (1)

Martin R
Martin R

Reputation: 540105

The members of CGPoint have the the type CGFloat, which is a Float on the 32-bit architecture and Double on the 64-bit architecture. Swift does not implicitly convert types. You can either use CGFloat consistently in your code, or add explicit casts:

var bgVelocity: CGPoint = CGPointMake(CGFloat(_pointsPerScndSpeed), 0.0)
var amToMove:CGPoint = CGPointMake(bgVelocity.x * CGFloat(_deltaTime), bgVelocity.y * CGFloat(_deltaTime))

Upvotes: 1

Related Questions