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 {/*www  .j a  v a  2s. c o  m*/
       print("User is a not member")
   }
}

Related Exercise