Swift - Data Type Boolean

Introduction

Swift supports the Boolean logic type-Bool.

A Bool type can take either a true or false value.

The following code snippet shows the Bool type in use:

Demo

var skyIsBlue = true
var seaIsGreen = false
var isOK:Bool = true

skyIsBlue = !true   //skyIsBlue is now false
print(skyIsBlue)  //false

Result

Bool variables are often used in conditional statements such as the If statement:

if isOK {
    print("OK")
} else {
    print("Not OK")
}