问题
Xcode is giving me this error message:
Document references must have an even number of segments, but users/hsiYfWgKz7MVOM77gMPkQYBHYJH2/wishlists has 3'
I have no idea why that error occurs because I thought there are 4 segments with this code:
let wishListName = self.popUpView.popUpTextField.text!
let db = Firestore.firestore()
let userID = Auth.auth().currentUser!.uid
db.collection("users").document(userID).collection("wishlists").document(wishListName).setData(["name": wishListName]) { (error) in
if error != nil {
print("Error saving Wishlist")
}
}
Note: The document(wishListName) does not exist before. I am trying to auto save it with the specific ID wishListName. Every help ist appreciated :)
回答1:
This typically happens when userID or wishListName is empty, as you end up with only 3 segments in that case.
If you log these values right before the line of code that throws an error, you can find out which one of the two is empty.
来源:https://stackoverflow.com/questions/59330958/swift-firestore-document-references-must-have-an-even-number-of-segments-but