По сути, я пытаюсь сделать следующее: после касания postTaskButton скопируйте информацию из titleTextField в новый документ в коллекции «prtasks», а затем скопируйте ее в личный документ текущего пользователя, вошедшего в систему, в папке « users "collection.
Для этого я попытался выполнить пакетную запись после нажатия кнопки« 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.")
}
}
}