Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't use method "contains" in Swift 2

Tags:

swift2

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

like image 682
Progr3ss Avatar asked Jun 15 '15 07:06

Progr3ss


2 Answers

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)
like image 91
Qbyte Avatar answered Sep 30 '22 18:09

Qbyte


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

like image 36
Narendra G Avatar answered Sep 30 '22 16:09

Narendra G