【问题标题】:How to set multiple values in Firebase Database using Swift?如何使用 Swift 在 Firebase 数据库中设置多个值?
【发布时间】:2017-09-07 13:32:47
【问题描述】:
@IBAction func addPost(_ sender: Any) {
    ref?.child("Posts").childByAutoId().setValue(titleText.text)
}

如果我想在帖子中添加小节而不仅仅是标题怎么办。比如日期作者

【问题讨论】:

    标签: ios swift firebase dictionary firebase-realtime-database


    【解决方案1】:

    创建一个常规的Swift dictionary,设置所需的属性,然后使用与上述相同的语法调用setValue

    例如:

    let ref: FIRDatabaseReference = ...
    let post = [
        "title":  "Incompleteness Theorem", 
        "author": "Kurt Gödel",
        "date":   "1931"
    ]
    ref.child("Posts").childByAutoId().setValue(post)
    

    【讨论】:

      猜你喜欢
      • 2018-01-28
      • 1970-01-01
      • 2020-01-07
      • 2016-11-16
      • 2017-09-29
      • 2017-04-13
      • 1970-01-01
      • 2013-09-21
      • 1970-01-01
      相关资源
      最近更新 更多