Alessandro
Alessandro

Reputation: 4100

Subtraction of CGFloats, ambiguity error Swift 3

I am trying to subtract some CGFloats, that are defined in this way:

var panelHeight:CGFloat!

When I try to do (screenHeight - panelHeight - tabBarHeight) in the following code, I get an error saying that I cannot apply a binary operator on CGFloat and CGFloat!, which doesn't make much sense, because all three floats are declared with !. If I replace tabBarHeight with tabBarHeight!, then I get an error called "Ambiguous reference to member -".

collisionBehavior.addBoundaryWithIdentifier("upperBoundary" as NSCopying, fromPoint: CGPoint(x: 0, y: screenHeight - panelHeight - tabBarHeight), toPoint: CGPoint(x: boundaryX, y: screenHeight - panelHeight - tabBarHeight))

Upvotes: 0

Views: 819

Answers (1)

Tim Vermeulen
Tim Vermeulen

Reputation: 12562

I can't find the bug report, but this is a known bug. A workaround is to cast the first or the second variable to a non-optional, like so:

(screenHeight as CGFloat) - panelHeight - tabBarHeight

Upvotes: 2

Related Questions