Progr3ss
Progr3ss

Reputation: 161

Can't use method "contains" in Swift 2

I am using Swift 2.

I used this code:

while contains(currentCardValues, randomNumber + 1) {

I am getting this error:

"contains" is unavailable: call the contains() method on the sequence

Upvotes: 11

Views: 6767

Answers (2)

Qbyte
Qbyte

Reputation: 13283

This is because the contains() method is defined in a protocol extension of Sequence. So you should call it this way:

currentCardValues.contains(randomNumber + 1)

Upvotes: 30

Narendra G
Narendra G

Reputation: 569

Please check this code:

    let array = [34, 56, 76, 77, 75]
    if array.contains(34) {
        print("contains")
    }else {
        print("Not Contains")
    }

Here contains() returns bool value

Upvotes: 4

Related Questions