Stats

Contributors: 2 Thursday, July 21, 2016
Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Rip Tutorial: riptutorial@gmail.com
Roadmap: roadmap

Negate a Bool with the prefix ! operator

Download swift eBook

Example

The prefix ! operator returns the logical negation of its argument. That is, !true returns false, and !false returns true.

print(!true)  // prints "false"
print(!false) // prints "true"

func test(_ someBoolean: Bool) {
    if !someBoolean {
        print("someBoolean is false")
    }
}