iOS Firebase 获取值等于某物的数据

标签 ios swift firebase firebase-realtime-database

我如何从 firebase 获取 swift3 中值等于某个值的数据。

在 MySQL 中将是 "SELECT * FROM users WHERE type = 'brown'"; 我如何在 Firebase 中编写 where 部分?

我有这个数据库

enter image description here

我想从 month == currentMonth 中获取所有数据(我有一个 currentMonth 变量)

最佳答案

您可以像这样查询:

let ref = Database.database().reference()
ref.child("Budget")
    .queryOrdered(byChild: "Month")
    .queryEqual(toValue: "November")
    .observe(.value, with: { (snapshot: DataSnapshot) in

        var array:[Budget] = []

        for budgetChild in snapshot.children {
            let budgetSnapshot = budgetChild as! DataSnapshot
            let budgetDictionary = budgetSnapshot.value as! [String:String]

            let budget: Budget = Budget()
            budget.description_ = budgetDictionary["Description"]
            budget.month = budgetDictionary["Month"]
            budget.type = budgetDictionary["Type"]
            budget.value = budgetDictionary["Value"]

            array.append(budget)
        }
    })

关于iOS Firebase 获取值等于某物的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47273903/

相关文章:

swift - NSNotificationCenter:在 Swift 中删除观察者

ios - 专门使用这行代码时无法解包值

javascript - 监听子列表的变化

ios - Firebase 更改显示在谷歌登录警报上的应用程序名称?

python-3.x - 有没有办法从 firebase 应用程序分发中以编程方式下载应用程序?

ios - ld : library not found for -lBolts

iOS swift 3 : does retain cycle happens in this case?

ios - Swift 1.2 文档更改(Markdown 支持)

ios - TableViewController 中 SearchBar 中的取消按钮需要双击

ios - 没有缓存的 Afnetworking 离线模式(像 Android 中的 Imageloader 一样保存到文件中)