When I want to check if an Optional Bool is true, doing this doesn\'t work:
var boolean : Bool? = false
if boolean{
}
It results in this error:
The answer I found most easy to read is to define a function. Not very complicated but does the work.
func isTrue(_ bool: Bool?) -> Bool {
guard let b = bool else {
return false
}
return b
}
usage:
let b: Bool? = true
if isTrue(b) {
// b exists and is true
} else {
// b does either not exist or is false
}