I ran into this using this innocent-looking piece of code:
func foo(line: CTLine) {
let ascent: CGFloat
let descent: CGFloat
let leading: CGFloat
let fWidth = Float(CTLineGetTypographicBounds(line, &ascent, &descent, &leading))
let height = ceilf(ascent + descent)
// ~~~~~~ ^ ~~~~~~~
}
And found the solution by expanding the error in the Issue Navigator:

Looking into it, I think Swift found the +(lhs: Float, rhs: Float) -> Float
function first based on its return type (ceilf
takes in a Float
). Obviously, this takes Float
s, not CGFloat
s, which shines some light on the meaning of the error message. So, to force it to use the right operator, you gotta use a wrapper function that takes either a Double
or a Float
(or just a CGFloat
, obviously). So I tried this and the error was solved:
// ...
let height = ceilf(Float(ascent + descent))
// ...
Another approach would be to use a function that takes a Double
or CGFloat
:
// ...
let height = ceil(ascent + descent)
// ...
So the problem is that the compiler prioritizes return types over parameter types. Glad to see this is still happening in Swift 3 ;P