Search code examples
swiftsqrt

How to solve Ambiguous Reference to Member 'sqrt' error?


So I've got this error,

ambiguous use of sqrt

destination = CGPoint(x: flies.position.x-25+CGFloat(arc4random_uniform(50)), 
y: flies.position.y-25+CGFloat(arc4random_uniform(50)))

squaredX = (Int(destination.x)-Int(fly.position.x))*(Int(destination.x)-Int(fly.position.x))

squaredY = (Int(destination.y)-Int(fly.position.y))*(Int(destination.y)-Int(fly.position.y))

distance = sqrt(xy)

how would I fix it?


Solution

  • Make sure that variable xy is one of Double, Float, CGFloat. These are the three possible functions for sqrt.