ninefifteen ninefifteen - 6 months ago 187
iOS Question

Absolute value function abs() unavailable in Swift 3.0. Use abs(_:) free function?

I am converting a Swift iOS project to Swift 3.0 using Xcode 8 Beta 4. The absolute value function shows to be unavailable. Here is a code sample...

let myInt = -3
let myAbsoluteInt = abs(myInt)

The second line results in an error stating:
'abs' is unavailable: Please use the 'abs(_:)' free function



The code you're showing us works for me in Xcode 8 beta 4.

I suppose you have another, different issue causing this misleading error message.

For example, it could be a conflict if you have imported other libraries.

A quick workaround would be to use the complete type:

let myAbsoluteInt = Swift.abs(myInt)