Swift NOT
Swift NOT Operator !
is used to perform logical NOT operation on a boolean operand.
!
symbol is used for Logical NOT Operator in Swift.
NOT Operator takes one boolean value as operands on its right and returns the logical NOT of the operand.
The syntax of NOT Operator with the boolean operand is
! operand
Truth Table
The following truth table provides the output of OR operator for different values of operands.
operand | ! operand |
---|---|
true | false |
false | true |
Example
In the following Swift program, we will take different boolean values for operand and find the result of NOT operation on the operand.
main.swift
var a: Bool var result: Bool a = true result = !a print("!\(a) = \(result)") a = false result = !a print("!\(a) = \(result)")
Output
!true = false !false = true
Conclusion
Concluding this Swift Tutorial, we learned what Swift NOT Logical Operator is, and the output of NOT Operation for different boolean values as operand, with the help of swift program.