Ios 如何使用swift更新firebase firestore中的文档?

Ios 如何使用swift更新firebase firestore中的文档?,ios,swift,firebase,google-cloud-firestore,Ios,Swift,Firebase,Google Cloud Firestore,当我运行下面的代码时,我得到了这个错误 ['FIRESTORE内部断言失败:文档引用无效。文档引用必须有偶数个段,但用户有1'] func saveLabel(uid: String, label: String){ let userRef = db.collection("User").document(uid) userRef.updateData(["label": label]) { (error) in

当我运行下面的代码时,我得到了这个错误

['FIRESTORE内部断言失败:文档引用无效。文档引用必须有偶数个段,但用户有1']

func saveLabel(uid: String, label: String){
  
    let userRef = db.collection("User").document(uid)
    
    userRef.updateData(["label": label]) { (error) in
        if error == nil {
            print("updated")
        }else{
            print("not updated")
        }
        
    }

}

此错误几乎肯定意味着
uid
为空。你应该把它记录下来以确定。

我把它修好了。uid因为某种原因返回零,但现在它工作了你是对的,返回零,我修正了它。谢谢如果您觉得这个答案很有用,通常在堆栈溢出时使用左边的按钮将其向上投票并标记为正确。