Reputation: 41
so I'm having a problem with my contains method in beta 5. specifically it says it is unavailable when using this code:
class func createSlot(currentCards: [Slot]) -> Slot {
var currentCardValues:[Int] = []
for slot in currentCards {
currentCardValues.append(slot.value)
}
var randomNumber:Int = Int(arc4random_uniform(UInt32(13)))
while contains(currentCardValues, randomNumber + 1) {
randomNumber = Int(arc4random_uniform(UInt32(13)))
}
Any help would be appreciated, not sure if it is a problem with the beta or just my new working with Swift 2, as it works in Xcode 6
Upvotes: 1
Views: 595
Reputation: 23616
The problem is that contains()
is no longer a global method that accepts a sequence as an argument. Instead, the method must be called on the sequence
In your case, you should change contains(currentCardValues, randomNumber + 1)
to currentCardValues.contains(randomNumber + 1)
Swift 1.x
let myNumbers: [Int] = [0, 1, 2, 3, 4]
let number: Int = 3
let contains: Bool = contains(myNumbers, number) //true
Swift 2.x
let myNumbers: [Int] = [0, 1, 2, 3, 4]
let number: Int = 3
let contains: Bool = myNumbers.contains(number) //true
Upvotes: 2