The magnitude of this value.
- Xcode 8.3+
- Swift Standard Library
For any numeric value
x is the absolute value of
x. You can use the
magnitude property in operations that are simpler to implement in terms of unsigned values, such as printing the value of an integer, which is just printing a ‘-’ character in front of an absolute value.
abs(_:) function provides more familiar syntax when you need to find an absolute value. In addition, because
abs(_:) always returns a value of the same type, even in a generic context, using the function instead of the
magnitude property is encouraged.