【问题标题】:How can I add a new document with fields to a firebase collection with the autoid in swift ui如何在swift ui中使用autoid将带有字段的新文档添加到firebase集合
【发布时间】:2020-01-19 17:11:06
【问题描述】:

我想使用 autoid 将文档添加到我的数据库集合中,其中包含我在 swift ui 中为其分配名称的字段。

【问题讨论】:

    标签: swift firebase google-cloud-firestore swiftui


    【解决方案1】:

    获取数据库的引用:

    var db: Firestore!
    

    然后你可以参考它:

    db.collection()
    

    例如,如果我想在唯一 id 下添加一个人的姓名:

    db.collection("users").addDocument(data: [
    "name": nameTextField.text // Change this to the variable you want to save
    ]) { err in
    if let err = err {
        print("Error writing document: \(err)")
    } else {
        print("Document successfully written!")
    }
    }
    

    如果您创建的文档没有明确的 Id,我们的 SDK 会自动为您随机生成一个。

    docs 也是一个很好的信息来源。

    【讨论】:

      猜你喜欢
      • 2021-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-08
      • 2019-06-16
      • 2021-08-19
      • 2021-06-27
      • 1970-01-01
      相关资源
      最近更新 更多