-
Book Overview & Buying
-
Table Of Contents
Mastering Swift 5.3 - Sixth Edition
By :
Boolean values are often referred to as logical values because they can be either true or false. Swift has a built-in Boolean type that accepts one of the two built-in Boolean constants: true and false.
Boolean constants and variables can be defined like this:
let swiftIsCool = true
var itIsRaining = false
Boolean values are especially useful when working with conditional statements, such as the if, while, and guard statements. For example, what do you think this code would do?
let isSwiftCool = true
var isItRaining = false
if isSwiftCool {
print("YEA, I cannot wait to learn it")
}
if isItRaining {
print("Get a rain coat")
}
If you answered that this code would print out YEA, I cannot wait to learn it, then you would be correct. This line is printed out because the isSwiftCool Boolean type is set to true, while the isItRaining variable is set to false; therefore, the Get a rain coat message is not printed.
In...