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

标签 ios swift firebase dictionary firebase-realtime-database

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

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

最佳答案

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

例如:

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

关于ios - 如何使用 Swift 在 Firebase 数据库中设置多个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43358188/

相关文章:

arrays - 使用无效数据调用函数FieldValue.arrayUnion()。 FieldValue.serverTimestamp()只能与update()和set()一起使用

iphone - 如何创建自定义 UIViewController 过渡动画?

ios - 将 CGRectMake (x,x,x,x) 更改为不同的位置,例如 (y,y,y,y)

ios - SwiftLint - 禁用特定文件中的行长规则

ios - IGListKit:获取当前可见的单元格索引

database - 如何为 firestore 创建自动删除机制? (删除时间段后的数据)

iOS:调试简单的 UI 滞后(我猜是基于 CoreData)

ios - 原生 iOS 应用程序的服务器端移动基础设施

swift - 当用户已经通过身份验证时,它会在转到 MainController 之前显示 LoginViewController 大约半秒钟

ios - 无法使用类型为 'setValue' 的参数列表调用 '(Any?, (Error?, DatabaseReference) -> Void)'