本文介绍了Swift-Firestore文档引用必须具有偶数个段,但是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Xcode给我这个错误消息:

Xcode is giving me this error message:

我不知道为什么会发生此错误,因为我认为这段代码有4个段:

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")
        }
    }

注意: document(wishListName)以前不存在.我正在尝试使用特定ID wishListName 自动保存它.每个帮助专家都感激:)

Note: The document(wishListName) does not exist before. I am trying to auto save it with the specific ID wishListName. Every help ist appreciated :)

推荐答案

userID wishListName 为空时,通常会发生这种情况,因为您最终在其中只有3个句段这种情况.

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.

这篇关于Swift-Firestore文档引用必须具有偶数个段,但是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 10:01