Operator

!(_:)

Performs a logical NOT operation on a Boolean value.

Declaration

prefix static func ! (a: Bool) -> Bool

Parameters

a

The Boolean value to negate.

Discussion

The logical NOT operator (!) inverts a Boolean value. If the value is true, the result of the operation is false; if the value is false, the result is true.

var printedMessage = false

if !printedMessage {
    print("You look nice today!")
    printedMessage = true
}
// Prints "You look nice today!"

See Also

Transforming a Boolean

func toggle()

Toggles the Boolean variable’s value.

static func || (Bool, () -> Bool) -> Bool

Performs a logical OR operation on two Boolean values.

static func && (Bool, () -> Bool) -> Bool

Performs a logical AND operation on two Boolean values.