我想更新firestore
db中的数据库字段,并且每次我调用函数时,应用都会出错:
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
这里是函数:(请注意,此函数位于完整代码中调用按钮的位置)
private func updateDocument() {
// [START update_document]
let testingDataChange = db.collection("homeBase").document("78kBh2c2OeNN8aTazMmz")
// Set the "capital" field of the city 'DC'
testingDataChange.updateData([
"armMove": true
]) { err in
if let err = err {
print("Error updating document: \(err)")
} else {
print("Document successfully updated")
}
}
// [END update_document]
}
我在单击按钮时在这里调用
@IBAction func loginTap(_ sender: Any) {
updateDocument()
}
点击按钮后,错误就会发生,应用会停止。
答案 0 :(得分:0)
您的firestore代码很好。问题出在快速代码中。尝试右键单击情节提要中的按钮,将其与代码断开连接,然后重新连接。