I have messageList which has all the messages in the chat. I want to remove only one message with the specific messageId but .remove only asks for index as Int. How can I remove that message from the messageList?
func deleteMessage(_ message: ChatMessageViewModel) {
let messageID = message.messageId
messageList.remove(object: messageID)
messagesCollectionView.reloadData()
}
CodePudding user response:
Try below code:
func deleteMessage(_ message: ChatMessageViewModel) {
let messageID = message.messageId
messageList.removeAll(where: { $0.messageId == messageID })
messagesCollectionView.reloadData()
}