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
.
Ideas?
The abs() function returns the absolute value of a number, which is a way of describing how far away from zero it is without thinking about whether it's positive or negative. It's most commonly used if you have a number that you need to be positive, because whether you pass 30 or -30 to abs() you get back 30.
Returns the absolute value of each element in a vector.
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)
You can try explicit Int
as parameter as mentioned here it may be a bug :
Ambiguous use of operator '-' in Swift with 'abs()'
let myInt:Int = -3
let myAbsoluteInt = abs(myInt)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With