ios - swift ,iOS : How do I extract data from my firebase database?

标签 ios swift firebase firebase-realtime-database

database

这是我的 Firebase 数据库。
我希望通过我的数据库来获取每张票的值,例如“忽略”、“彼得兔子......”、“超人总动员2......”等。

目前我正在提取这样的数据:

ref = Database.database().reference()
let uid = Auth.auth().currentUser?.uid
ref?.child("users").child(uid!).observe(.childAdded, with: { (snapshot) in
    if let userDict = snapshot.value as? [String:String] {
        self.movieNameFromTickets.append(myValue)
    }

})    

但我觉得这不是提取数据的好方法,因为如果我有其他结构(例如票证),它可能会打印出错误的信息。

提取我的门票值(value)的更好方法是什么?
谢谢:)

最佳答案

试试这个:

Database
    .database()
    .reference()
    .child("Users")
    .child(Auth.auth().currentUser!.uid)
    .child("Advertisements")
    .queryOrderedByKey()
    .observeSingleEvent(of: .value, with: { snapshot in

        guard let dict = snapshot.value as? [String:Any] else {
            print("Error")
            return
        }
        // get value from dict here .
    })

关于ios - swift ,iOS : How do I extract data from my firebase database?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50404018/

相关文章:

javascript - 火力地堡 'A network error (such as timeout, interrupted connection or unreachable host) has occurred.'

ios - 当库没有发布 podspec 时,解决 cocoapods 中的依赖关系

ios - 存档 iOS 应用程序时出错 - "generic specialization <Swift.String> of Swift.String.init"

ios - 对讲机 : iOS App crashing on updating user only on iOS 10. 3.2

ios - 以编程方式使用按钮将 ViewController 推送到 UICollectionviewController Swift

java - Firebase 数据库空对象引用

ios - UITableViewController自定义setEditing:animated:

ios - 使用 iBooks App Dictionary 检查单词定义

objective-c - 获取文件的 QuickLook 预览图像

firebase - 如何允许用户查询集合但只能访问集合中的某些结果?