Swift - Write program to fix bug in optional type

Requirements

The following code snippets cause the compiler to generate an error. Fix it.

var isMember :Bool?
if isMember {
    print("User is a member")
} else {
    print("User is a not member")
}

Hint

You should ensure that isMember is not nil before using it.

Then unwrap it using the ! character:

Demo

var isMember:Bool?
if isMember != nil {
   if  isMember!  {
       print("User is a member")
   } else {// ww w . j a va 2 s. c om
       print("User is a not member")
   }
}

Related Exercise