Xcode 7 Beta 5中的contains() [英] contains() in Xcode 7 Beta 5

查看:86
本文介绍了Xcode 7 Beta 5中的contains()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在beta 5中的contains方法有问题,特别是它说使用此代码时不可用:

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)))
    }

任何帮助将不胜感激,不确定是Beta的问题还是仅仅是我的Swift 2的新问题,因为它可以在Xcode 6中工作

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

推荐答案

问题是contains()不再是接受序列作为参数的全局方法.相反,必须在序列上调用该方法

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

在您的情况下,应将contains(currentCardValues, randomNumber + 1)更改为currentCardValues.contains(randomNumber + 1)

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

这篇关于Xcode 7 Beta 5中的contains()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆