检查一个数组是否包含另一个数组 swift

Check if an array contains another array swift

在我的应用程序中,我正在尝试检查并查看是否有 2 个用户已经在我的 AWS DynamoDB table 中创建了对话,如果没有,将创建用户之间的对话。我使用列表查询功能检查并查看是否创建了 currentUserSubrecieverUserSub 数组,但我收到一条错误消息

Binary operator '==' cannot be applied to operands of type 'Conversation.CodingKeys' and '[String]'

Conversations 在其 table 命名成员中有一个字段,它是一个字符串数组值。

这是我的代码:

    let conversations = Conversation.keys
        let predicate = conversations.members == [currentUserSub, recieverUserSub] // this is where I get the error
        _ = Amplify.API.query(request: .list(Conversation.self, where: predicate)) { event in
            switch event {
            case .success(let result):
                switch result {
                case .success(let convo):
                    print("Successfully retrieved the convo: \(convo)")

                case .failure(let error):
                    print("Got failed result with \(error.errorDescription)")
                }
            case .failure(let error):
                print("Got failed event with error \(error)")
            }
        }

我该如何解决这个问题?

我从放大文档中引用了这个函数https://docs.amplify.aws/lib/graphqlapi/query-data/q/platform/ios#list-query

试试这个

let predicate = conversations.members.contains(currentUserSub) && conversations.members.contains(recieverUserSub)