init(booleanLiteral:)
Creates an instance initialized to the specified Boolean literal.
Declaration
init(booleanLiteral value: Bool)Parameters
- value:
The value of the new instance.
Discussion
Do not call this initializer directly. It is used by the compiler when you use a Boolean literal. Instead, create a new Bool instance by using one of the Boolean literals true or false.
var printedMessage = false
if !printedMessage {
print("You look nice today!")
printedMessage = true
}
// Prints "You look nice today!"In this example, both assignments to the printedMessage variable call this Boolean literal initializer behind the scenes.