Checking of presence of a value in nullable types in Swift
Forums:
let n1: Int? = 42
var exists = n1 != nil
//exists is true
let n2: Int? = nil
exists = n2 != nil
//exists is false
let nCharA: Character? = "A"
if let charA = nCharA {
exists = true
print("charA is \(charA)")
} else {
exists = false
}
//exists is true
- Log in to post comments