【发布时间】:2019-04-25 04:03:51
【问题描述】:
尝试在 iOS 中使用 swift 使用 firebase FieldValue.increment(1) 时收到编译器错误。错误只说“模糊使用'increment'”
我已将我的所有 pod 更新为所有使用的 firebase pod 的当前版本。更具体地说,我在 Firebase(5.20.2) 和 FirebaseFirestore (1.2.1) 上。
我的代码(如下)与文档Seen at the bottom of this page中的示例几乎完全相同
如何修复此错误并让应用程序编译?
let docRef = db.collection("metadata").document("permanentConversions")
docRef.updateData([
"total": FieldValue.increment(1)
])
【问题讨论】:
-
你需要使用
docRef.updateData(["total":firebase.firestore.FieldValue.increment(1)]) -
引用您的 Firebase 导入
-
这给出了另一个错误“使用未解析的标识符‘firebase’;你的意思是‘FirebaseApp’吗?”并尝试
FirebaseApp.firestore.FieldValue.increment(1)给出错误“类型'FirebaseApp'没有成员'firestore'” -
hmm ..我认为你这样做的方式很好,但不确定为什么不起作用,我想说确保你的导入是好的,你的 firebase 和 firestore 的初始化是好的。并查看此链接以及他们是如何做到的:github.com/firebase/snippets-ios/blob/master/firestore/swift/…
-
@MichaelMcKenna 我也有错误。我将我的应用程序更新为 Swift 5,但错误仍然存在。如果我找到了解决办法,我一定会在这里发布 - 如果你找到了,请告诉我!
标签: firebase google-cloud-firestore