ios - 遍历 firebase 数据库

标签 ios swift firebase firebase-realtime-database ios10

Swift 3.x iOS 10。

尝试了解 firebase 中的数据库。将一些 JSON 数据导入到我的应用程序中并设法将其读回。这是代码。

let rootRef = Database.database().reference(withPath: "0")
print("\(rootRef.key)")   
let nextRef = rootRef.child("identity")
print("\(nextRef)")

nextRef.observe(.value, with: { snapshot in
    print("\(snapshot.value)")
}) 

这有效,我的数据看起来像这样......

Firebase database

但是,如果我想遍历数据库,查看记录 2、记录 3 等,而我不确定实际有多少记录,该怎么做。

最佳答案

好的,我找到了,很好用的东西......

let rootRef = Database.database().reference()
rootRef.observe(.value, with: { snapshot in
    print("dump \(snapshot.children.allObjects)")
})

我发帖是为了后代:)

关于ios - 遍历 firebase 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46412596/

相关文章:

ios - 适用于 iOS 的 Firebase 集成示例 (FriendlyPix)

ios - swifyJson突然无法解析alamofire数据

ios - 状态栏在模拟指标中改变颜色 swift ios

ios - 从 api 获取图像并在 UIImageView swift 中显示它们

javascript - Angular Firebase 2 检查用户是否存在然后添加到数据库

android - 如何在 firebase 中检查用户电子邮件和密码验证以登录

android - firebase 电话身份验证失败并出现 MISSING_CLIENT_IDENTIFIER

objective-c - NSUrlConnection 不起作用。我没有得到任何回应

ios - 在 iOS Xcode 中正确使用纵横比纵横填充

ios - 边框未应用于全 View