@IBAction func addPost(_ sender: Any) {
ref?.child("Posts").childByAutoId().setValue(titleText.text)
}
如果我想添加子部分而不仅仅是标题,该怎么办?例如 date , authors 等
答案 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)