【发布时间】:2020-08-18 19:01:53
【问题描述】:
我正在编写快速编程,但每次我运行我的应用程序时,它都会突然崩溃。 我得到的错误信息是
线程 1:异常:“FIRESTORE INTERNAL ASSERTION FAILED: Invalid document reference。文档引用必须有偶数个段,但 NewGame 有 1 个”
我搜索了错误,人们说如果我在 db 中有多个集合和文档,它往往会发生。但是我的数据库真的很简单。只有两个集合,其中我有文件。喜欢这张图。
当我点击一个条形按钮时,应用程序崩溃了,就是这行代码。
@IBAction func addPressed(_ sender: UIBarButtonItem) {
performSegue(withIdentifier: K.homeToGameScreen, sender: self)
// create new game array in db & player's ready status -> true
db.collection(K.FStore.newGameCollection)
.addDocument(data: [K.FStore.gameBoardField: GameBoard.gameBoard, K.FStore.player1Field: playerInfo[K.FStore.nameField]!, K.FStore.player2Field: K.FStore.player2Field, K.FStore.uID: playerInfo[K.FStore.uID]!]) { (err) in
if let err = err {
print("Error getting documents3: \(err)")
} else {
self.db.collection(K.FStore.playersCollection).document(self.docId).updateData([K.FStore.isReadyField: true]){ err in
if let err = err {
print("Error updating player's isReady status: \(err)")
} else {
print("Document successfully updated")
}
}
}
}
}
上面的代码在一个叫做 HomeViewController 的地方,但我总是在 AppDelegate.swift 文件中出错。
谁能告诉我这里发生了什么以及如何解决这个问题?
【问题讨论】:
-
你最终找到出路了吗?
标签: swift firebase google-cloud-firestore