Declare Boolean Variable
To declare a variable of type Bool in Swift, use
: Bool after the variable name.
var isAvailable: Bool
Let us write a swift program, in which we declare a variable with the name
isAvailable, and declare this variable as type
Bool. Later, we will assign a value
true to this variable and print it.
import Foundation var isAvailable: Bool isAvailable = true print(isAvailable)
The type of the variable
Bool, because of which we could assign a boolean value to the variable.
We can also programmatically check the type of the variable
import Foundation var isAvailable: Bool print(type(of: isAvailable))
We have learnt how to declare a variable of type Bool in Swift.