简体   繁体   中英

Swift - Firestore Document references must have an even number of segments, but

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 :)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM