首页 > 解决方案 > 为什么 FieldValue.increment() 在 Swift 中给我一个错误?

问题描述

所以我唯一改变的是添加:

pod 'Geofirestore'

使用 Firestore 到我的 IOS 应用程序的 podfile,其中包含以下内容:

  pod 'Firebase/Core'
  pod 'Firebase/Firestore'
  pod 'Firebase/Auth'
  pod 'Firebase/Storage'
  pod 'GooglePlaces'
  pod 'GoogleMaps'
  pod 'Geofirestore'
  pod 'InstantSearch', '~> 5.0'

突然间,我在 Firestore 中更新字段值的代码行抛出了错误。这些行:

db.collection("people").document(userID!).updateData(["listsCount": FieldValue.increment(Int64(1))])

现在给我错误:

类型“FieldValue”没有成员“增量”

对于我的生活,我无法弄清楚突然发生了什么变化。任何帮助表示赞赏。

标签: iosswiftfirebasegoogle-cloud-firestoregeofirestore

解决方案


我能够通过Double在更新字段之前将我的值初始化为 a 来解决此问题。这样,Firebase 知道如何解释增量,可以是DoubleInt64

   let value: Double = 1

    ref.updateData([
        "likeCount" : FieldValue.increment(value)

    ])

推荐阅读