Swift 'fabs' is deprecated: renamed to 'abs'

Viewed 642

When I try using fabs on a CGFloat number in Swift 5, I get this warning:

'fabs' is deprecated: renamed to 'abs'

But when I use abs, it's argument is only Integer, not Float or Double. I am using XCode 12 if that matters. How do I resolve this?

2 Answers

You're probably using abs from the Foundation framework.

Try the following:

Swift.abs(CGFloat(1.0))

Foundation.abs(CGFloat(1.0)) // Cannot convert value of type 'CGFloat' to expected argument type 'Int32'
Swift.abs(CGFloat(1.0)) // Compiles successfully
Related