swift2 - 不能在 Swift 2 中使用方法 "contains"

标签 swift2

我正在使用 Swift 2。

我使用了这段代码:

while contains(currentCardValues, randomNumber + 1) {

我收到此错误:

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

最佳答案

这是因为 contains()方法在 Sequence 的协议(protocol)扩展中定义.
所以你应该这样称呼它:

currentCardValues.contains(randomNumber + 1)

关于swift2 - 不能在 Swift 2 中使用方法 "contains",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30839733/

相关文章:

ios - 我正在用 Swift 编写 iOS 应用程序。我应该使用单例吗?

uitableview - 向 searchBar 添加索引

swift - 在 Swift 中创建的 CFSocket 不监听

swift - 尝试扩展 IntegerType(和 FloatingPointType);为什么不能将所有 Int 类型都转换为 NSTimeInterval

ios - 将一个球放入一个被困在里面的矩形内,并具有一定的速度和恢复力

ios - 在 Alamofire 2.0 中使用客户端证书

iOS Swift 如何从分割 View 返回到普通 View Controller

swift - 集合类型过滤器 : Swift compilation error : Tuple pattern cannot match values of non-tuple type

arrays - 如果两个数组包含相同的元素,无论这些元素出现的顺序如何,我如何检查 Swift?

ios - Swift:无法将类型 '__NSCFArray' 的值转换为 'NSDictionary'