Khoury Khoury - 4 months ago 22
iOS Question

Binary operator '&&' cannot be applied to operands of type bool and string

I am trying to change the number of items within a variable when they are purchased in-app.

In the UICollectionView, I want to have a condition where if the stringforkey from UserDefaults is equal to two strings, then the following code will be used.

Here it is

else if userDefault.stringForKey("purchases") == "unlockthemecoll2" && "unlockthemecoll1"


Why can't I do this, I get the error written in the title of this question.

Thanks

Answer

userDefault.stringForKey("purchases") can't have two values at the same time.

If you want to check whether it has one of the values or the other, you should do that :

else if userDefault.stringForKey("purchases") == "unlockthemecoll2" || userDefault.stringForKey("purchases") == "unlockthemecoll1"
Comments