mardi 7 avril 2020

Comparing non-optional value of type 'Bool' to 'nil' always returns true

I have an if-else statement where I am checking if the value coming from user defaults is nil or not like this:

 if defaults.bool(forKey: "abcd") != nil{
       //Do something
    }
    else{
        //do something else
    }

But Xcode is giving me an error saying: "Comparing non-optional value of type 'Bool' to 'nil' always returns true"

Can someone explain what's happening here and how to fix this?

Aucun commentaire:

Enregistrer un commentaire