【问题标题】:Firebase not saving data from loop generated iOS dataFirebase 没有从循环生成的 iOS 数据中保存数据
【发布时间】:2017-01-31 17:58:11
【问题描述】:

我正在尝试使用循环在我的 iOS Firebase 数据库中填充一些数据,但它似乎只保存了最后一个值。有点难过:/

while (counter < 50){
patientName = newPatient.patientName + String(counter)

    FIRDatabase.database().reference().child("testTable").child("patient").setValue(patientName)
    FIRDatabase.database().reference().child("testTable").child("patient").child(patientName).child("patient DOB").setValue(newPatient.patientDOB)
    FIRDatabase.database().reference().child("testTable").child("patient").child(patientName).child("test var").setValue(newPatient.patienttest)
    FIRDatabase.database().reference().child("testTable").child("patient").child(patientName).child("test var 1").setValue(newPatient.patienttest1)
    counter += 1

}

这是我在控制台上看到的输出:

2017-01-31 09:48:25.999233 DemoTest[15969:1332318] [] __nwlog_err_simulate_crash simulate crash already simulated "nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available"
2017-01-31 09:48:25.999827 DemoTest[15969:1332318] [] nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available, dumping backtrace:

数据库只是添加/保存最后一个值:

【问题讨论】:

    标签: ios firebase swift3 firebase-realtime-database


    【解决方案1】:

    基本上我是在覆盖我的条目,而我应该输入的只是简单的 .child(patientName),然后剩下的我可以做 setValue。这全部来自 firebase 文档:

    获取指定相对路径处位置的 FIRDatabaseReference。相对路径可以是简单的子键(例如“fred”)或更深的斜线分隔路径(例如“fred/name/first”)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多