【发布时间】:2021-05-27 01:53:14
【问题描述】:
感谢您查看不确定我缺少什么?
这是我的数据在 Firestore 中的样子
这里是评论模型。请注意,我应该在原始问题中显示这一点以获得更多上下文。
import SwiftUI
import FirebaseFirestoreSwift
struct Comment: Identifiable, Codable, Hashable {
var id: String
var userId: String
var storyId: String
var commentText: String
var createdAt: Date
}
这是我删除 Firestore 数据的方法。没有错误被抛出?方法中的打印语句打印预期的 Firestore 文档 ID 和有问题的整个评论对象,但它也打印成功案例,并且 UI 或 FireStore 中没有任何变化。
func deleteComment(id: String, comment: Comment) {
print(id, comment)
//prints firestore document id and whole comment object
let commentData: [String: Any] = [
"id" : comment.id as Any,
"userId" : comment.userId,
"storyId" : comment.storyId,
"commentText" : comment.commentText,
"createdAt" : comment.createdAt
]
store.collection(path).document(id).updateData([
"comments" : FieldValue.arrayRemove([commentData])
]) { error in
if let error = error {
print("Unable to delete comment: \(error.localizedDescription)")
} else {
print("Successfully deleted comment")
}
}
}
【问题讨论】:
-
您在第一个示例中使用“comment”(没有
s),在第二个示例中使用“cmets`(带有s)。 -
@jnpdx 谢谢我修正了我的错字。不过我还有事情发生
-
看起来
arrayRemove需要将整个对象传递给它——你只传递了id。 -
这看起来可能是同一个问题:stackoverflow.com/questions/67733560/…
-
@jnpdx 谢谢我刚刚看到你的评论,没错,是日期类型
标签: ios swift firebase google-cloud-firestore