如何使用Swift在Firebase数据库中设置多个值?

时间:2017-04-12 00:13:32

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

@IBAction func addPost(_ sender: Any) {
    ref?.child("Posts").childByAutoId().setValue(titleText.text)
}

如果我想添加子部分而不仅仅是标题,该怎么办?例如 date authors

1 个答案:

答案 0 :(得分:5)

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

例如:

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