What output will be produced by the code below?

let userLoggedIn: Bool? = false

if !userLoggedIn! {
    print("Message one")
} else {
    print("Message two")

Correct answer: "Message one".

Explanation: The (deliberately clumsy) expression !userLoggedIn! means, "force unwrap this boolean, then negate it." The userLoggedIn boolean is set to be false, so it will be true when negated, meaning that "Message one" will be printed.


© 2017