Swift Language Booleans What is Bool?

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9

Example

Bool is a Boolean type with two possible values: true and false.

let aTrueBool = true
let aFalseBool = false

Bools are used in control-flow statements as conditions. The if statement uses a Boolean condition to determine which block of code to run:

func test(_ someBoolean: Bool) {
    if someBoolean {
        print("IT'S TRUE!")
    }
    else {
        print("IT'S FALSE!")
    }
}
test(aTrueBool)  // prints "IT'S TRUE!"


Got any Swift Language Question?