Reputation: 39081
I have this function:
func isDrawRadiusEnough(let point: CGPoint) -> Bool {
let distance = sqrtf(powf(point.x-lastPointDrawn.x, 2)+powf(point.y-lastPointDrawn.y, 2))
return distance > drawRadius // Error: Could not find an overload for '>' that accepts the supplied arguments
}
drawRadius
is an Int
and is a property in the same class as the function. lastPointDrawn
is a CGPoint
and is also a property.
When I set the drawRadius
as a Float the error disappears, but I don't want it to be a float. In Obj-C this was valid but it is not in Swift. Anyone know a workaround?
Upvotes: 1
Views: 873
Reputation: 56352
sqrtf
returns a Float value.
Since drawRadius
is an Int
, you need to convert it to a Float
prior to performing the compare operation.
Try return distance > Float(drawRadius)
This is due to Swift's implementation of type safety. No implicit type conversions are performed.
Upvotes: 5