0

So I'm working on an application that has to check if one of the given values are in an array

if hand1.contains(0||13||26||39) {
            PresentA = true
        } else {
            PresentA = false
        }

Xcode keeps saying : "Cannot convert value of type 'Int' to expected argument type 'Bool'". I have no idea on what is wrong with this piece of code. I want this all in one if-statement because that would make my program a lot smoother.

It doesn't give me an error when I replace the double pipes with single ones. But I know that that those are bitwise or something and won't help with what I want.

if hand1.contains(0|13|26|39) {
            PresentA = true
        } else {
            PresentA = false
        }

I am currently using Xcode 11.3.1

John Montgomery
  • 6,739
  • 9
  • 52
  • 68
  • The problem is that you can only use `||` with boolean values. If you wanted to do it that way, you would have to do `hand1.contains(0) || hand1.contains(13)` and so on, but the duplicate I suggested has a shorter way of doing it. – John Montgomery Jul 20 '20 at 19:08
  • In this case you could easily flip the condition by using a simple array. It should be `if [0,13,26,39].contains(hand1)` – ram Jul 21 '20 at 01:19

0 Answers0