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

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

问题描述:

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

如果我想添加小节而不是标题,该怎么办。像日期作者如何使用Swift在Firebase数据库中设置多个值?

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

例如:

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