【问题标题】:Check if an array contains another array swift快速检查一个数组是否包含另一个数组
【发布时间】:2020-08-08 16:47:23
【问题描述】:

在我的应用程序中,我试图检查是否有 2 个用户已经在我的 AWS DynamoDB 表中创建了对话,如果没有,将创建用户之间的对话。我使用列表查询函数来检查是否创建了 currentUserSubrecieverUserSub 的数组,但我收到一个错误提示

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

Conversations 在其表中具有名为 members 的字段,该字段是字符串的数组值。

这是我的代码:

    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中引用了这个函数

【问题讨论】:

    标签: swift aws-amplify


    【解决方案1】:

    试试这个

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

    【讨论】:

      猜你喜欢
      • 2020-11-21
      • 2015-10-28
      • 2017-05-30
      • 1970-01-01
      • 2023-03-24
      • 2021-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多