首页 > 解决方案 > 将元素添加到 Firestore 数组时获取“类型‘FieldValue’没有成员‘arrayUnion’”

问题描述

当我在 Xcode 中使用此代码时:

let washingtonRef = db.collection("cities").document("DC")

// Atomically add a new region to the "regions" array field.
washingtonRef.updateData([
    "regions": FieldValue.arrayUnion(["greater_virginia"])
])

// Atomically remove a region from the "regions" array field.
washingtonRef.updateData([
    "regions": FieldValue.arrayRemove(["east_coast"])
])

这是Firebase Website中的一个示例,我收到以下错误:

Type 'FieldValue' has no member 'arrayUnion'

这个问题的任何解决方案?

标签: swiftfirebasegoogle-cloud-firestore

解决方案


这可能是因为您有一个“旧”版本的 iOS SDK。arrayUnion 功能已在 2018 年 8 月 2 日的版本 5.5.0 中实施。

有关更多详细信息,请参阅https://firebase.google.com/support/release-notes/ios


推荐阅读