【发布时间】:2020-05-13 21:37:08
【问题描述】:
我想在 TableView 中显示特定用户的所有现有聊天(姓名、LastMessage)的概览。
现在,我在 TableView 中添加了一个新项目,这显然是错误的,我想通过它的键“ChatId”来更新现有项目
这是我的模特:
class ChatModel {
var chatOwnerId: String?
var chatPartnerId: String?
var createdDate: Timestamp?
var chatId: String?
var lastMessage: String?
var lastMessageDate: Timestamp?
init(dictionary: [String: Any]) {
chatOwnerId = dictionary["chatOwnerId"] as? String
chatPartnerId = dictionary["chatPartnerId"] as? String
createdDate = dictionary["createdDate"] as? Timestamp
chatId = dictionary["chatId"] as? String
lastMessage = dictionary["lastMessage"] as? String
lastMessageDate = dictionary["lastMessageDate"] as? Timestamp
}
}
我如何将数据添加到我的模型中:
func loadChatOverviewNew(currentUser: String) {
ChatApi.shared.observeChatOverviewNew(currentUser: currentUser) { (chatOverview) in
self.chats.insert(chatOverview, at: 0)
self.chatTableView.reloadData()
}
}
当我收到新快照时如何更新我的“聊天”,而不是追加/插入它?
【问题讨论】:
标签: swift google-cloud-firestore