In my app I am trying to check and see if 2 users already have a conversation created inside of my AWS DynamoDB table and if not a conversation between the users will be created. I use the list query function to check and see if an array of currentUserSub
and recieverUserSub
is created but I am getting an error saying
Binary operator '==' cannot be applied to operands of type 'Conversation.CodingKeys' and '[String]'
Conversations has field in its table named members which is an array value of Strings.
Here is my code:
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)")
}
}
How could I go about fixing this?
I reference this function from the amplify docs https://docs.amplify.aws/lib/graphqlapi/query-data/q/platform/ios#list-query
try this
let predicate = conversations.members.contains(currentUserSub) && conversations.members.contains(recieverUserSub)