【问题标题】:Problem with updateData() function from FirestoreFirestore 中的 updateData() 函数存在问题
【发布时间】:2021-02-09 16:05:13
【问题描述】:

这是我在 Firestore 数据库中更新字段的代码:

private var db = Firestore.firestore()

func moveToNextWeek(){
    let newWeekOn = plan!.weekOn + 1
    db.collection("Users").document(Auth.auth().currentUser!.uid).collection("Plan").document("plan").updateData(["weekOn": newWeekOn])
}

但是我不断收到错误消息:Ambiguous use of 'updateData'。 我不明白为什么这个错误不断出现,有什么想法吗?

【问题讨论】:

  • 您的代码对我有用。强制解包选项可能很危险plan!currentUser!,因此最好在尝试将其编写为 nil 之前检查一下,您的代码会爆炸。

标签: swift firebase google-cloud-firestore compiler-errors


【解决方案1】:

可以通过将其分配给变量并添加.description来修复它。

let _ = db.collection("Users").document(Auth.auth().currentUser?.uid ?? "NO USER").collection("Plan").document("plan").updateData(["weekOn": newWeekOn]).description 但是,我不确定这是为什么。

【讨论】:

  • 这是一个答案吗?如果是这样,它不会很好地工作,也没有理由这样做(将其分配给 var 或添加 .description)。以这种方式留下代码,您将遇到重大问题。我会继续寻找其他地方,因为您问题中的代码是合法的并且可以正常工作。
猜你喜欢
  • 2020-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-12
  • 2023-04-10
相关资源
最近更新 更多