【发布时间】:2020-11-23 09:06:03
【问题描述】:
基本上,我要做的是,一旦点击 postTaskButton,将信息从 titleTextField 复制到“prtasks”集合中的新文档,然后将其复制到当前登录用户的个人文档中“用户”集合。
为此,我尝试在点击“PostTasks”按钮后执行批量写入。但是,Xcode 以粗体显示错误“无法将 'Query' 类型的值转换为预期的参数类型 'DocumentReference'”。
@IBAction func postTaskButton(_ sender: Any) {
let title = titleTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let db = Firestore.firestore()
let batch = db.batch()
//Copy the information from the form to the 'prtasks' root collection
let prtasksRef = db.collection("prtasks").document()
batch.setData(["title" : title], forDocument: prtasksRef)
//Copy the information from the form to a map entry in the user's personal tasks collection
let userTasksRef = db.collection("users").whereField("uid", isEqualTo: Auth.auth().currentUser?.uid ?? "")
**batch.setData(["title": title], forDocument: userTasksRef)**
//Commit all of the above batch writes to the firestore
batch.commit() { (error) in
if error != nil {
self.showAlert(for: "Error Writing Batch")
} else {
self.showAlert(for: "Batch write succeeded.")
}
}
}
【问题讨论】:
标签: swift database firebase google-cloud-firestore