使用另一个Swift检查数组的内容

使用另一个Swift检查数组的内容,swift,Swift,我有两个数组,我试图检查一个数组的内容是否存在于另一个数组中。然而,我有一个错误的崩溃 Thread 1: Fatal error: Duplicate elements of type 'Report' were found in a Set. This usually means either that the type violates Hashable's requirements, or that members of such a set were mutated after ins

我有两个数组,我试图检查一个数组的内容是否存在于另一个数组中。然而,我有一个错误的崩溃

Thread 1: Fatal error: Duplicate elements of type 'Report' were found in a Set.
This usually means either that the type violates Hashable's requirements, or
that members of such a set were mutated after insertion.
这是我用来检查的

extension Array where Element: Hashable {

    func set() -> Set<Array.Element> {
        return Set(self)
    }

    func isSubset(of array: Array) -> Bool {
        self.set().isSubset(of: array.set())
    }

    func isSuperset(of array: Array) -> Bool {
        self.set().isSuperset(of: array.set())
    }

    func commonElements(between array: Array) -> Array {
        let intersection = self.set().intersection(array.set())
        return intersection.map({ $0 })
    }

    func hasCommonElements(_ array: Array) -> Bool {
        return self.commonElements(between: array).count >= 1 ? true : false
    }
}

我不完全理解你的意思。哪个函数会产生错误,你能发布一个可复制的示例吗?这个函数
commonElements
,这是一行
self.set().intersection(array.set())
和一个可复制的示例。。。?也许可以添加报告的定义检查我添加的解释。
allTransactionHistory.hasCommonElements(reports)

struct Report: Hashable {

}