为什么我不能检查,看看是否我的数组的数组包含一个特定的阵列? [英] Why can't I check to see if my array of arrays contains a specific array?

查看:116
本文介绍了为什么我不能检查,看看是否我的数组的数组包含一个特定的阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查是否数组的数组包含字符串数组。我的错误消息说:

I'm trying to check to see if an array of arrays contains an array of Strings. My error message says:

不能为包含接受型([([(字符串)])]),[(字符串)])'参数列表中找到过载

"Cannot find an overload for 'contains' that accepts an argument list of type '([([(String)])]), [(String)])'"

var allCards = [[String]]()
var exp1 = [String]()

if !contains(allcards, exp1) {
    allCards.append(exp1)
}

这是怎么回事!?

What's going on!?

推荐答案

阵列不符合 Equatable 协议,因此

/// Return `true` iff `x` is in `seq`.
func contains<S : SequenceType where S.Generator.Element : Equatable>(seq: S, x: S.Generator.Element) -> Bool

不能在此处使用。您可以使用基于pdicate $ P $变种

cannot be used here. You can use the predicate-based variant

/// Return `true` iff an element in `seq` satisfies `predicate`.
func contains<S : SequenceType, L : BooleanType>(seq: S, predicate: @noescape (S.Generator.Element) -> L) -> Bool

而不是:

var allCards = [[String]]()
var exp1 = [String]()

if !contains(allCards, { $0 == exp1 } ) {
    allCards.append(exp1)
}

由于 == 被定义为 Equatable 元素的数组。

because == is defined for arrays of Equatable elements.

这篇关于为什么我不能检查,看看是否我的数组的数组包含一个特定的阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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