二元运算符 '&&' 不能应用于 bool 和 string 类型的操作数

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

我正在尝试在购买商品时更改变量中的商品数量 in-app。

在 UICollectionView 中,我想要一个条件,如果 UserDefaults 中的 stringforkey 等于两个字符串,那么将使用以下代码。

在这里

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

为什么我不能这样做,我得到这个问题标题中写的错误。

谢谢

userDefault.stringForKey("purchases")不能同时有两个值。

如果您想检查它是否具有其中一个值或另一个值,您应该这样做:

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