Operator

-(_:)

Returns the additive inverse of the specified value.

Declaration

prefix static func - (operand: Int) -> Int

Return Value

The additive inverse of the argument.

Discussion

The negation operator (prefix -) returns the additive inverse of its argument.

let x = 21
let y = -x
// y == -21

The resulting value must be representable in the same type as the argument. In particular, negating a signed, fixed-width integer type’s minimum results in a value that cannot be represented.

let z = -Int8.min
// Overflow error

See Also

Negation

static func + (Int) -> Int

Returns the given number unchanged.