I'm working on swift programming but every time I run my app, it suddenly starts crashing. The error message I got was
Thread 1: Exception: "FIRESTORE INTERNAL ASSERTION FAILED: Invalid document reference. Document references must have an even number of segments, but NewGame has 1"
I searched the error and people are saying if I have several collections and documents in db, it tends to happen. But my db is really simple. only two collections and inside of them I have documents. Like this image.
When I tap a bar button, the app crashes, which is this lines of code.
@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")
}
}
}
}
}
the code above are in something called HomeViewController, but I always get error in AppDelegate.swift file.
Could anyone please tell me what is going on here and how to fix this please?