ios - 使用 swift 3 在 Firebase 数据库上进行简单搜索

标签 ios swift database firebase firebase-realtime-database

我是 Firebase 的新手,在过去的两天里,我一直在尝试弄清楚如何在我的数据库上执行简单的搜索,但没有成功。

enter image description here

而且我想对所有子 channel 执行搜索。例如,我想搜索是否有名为 Klx0N4pxsBHGVkhYuY0 的 channel 。我试试

queryEqual(toValue: "Klx0N4pxsBHGVkhYuY0")

但没有运气。

非常感谢您抽出宝贵的时间和帮助。

最佳答案

您所要做的就是观察该路径,如果没有数据,snapshot.value 将为 nil。

let ref = FIRDatabase.database().reference().child("channels").child("Klx0N4pxsBHGVkhYuY0")

ref.observeSingleEvent(of: .value, with: { (snapshot) in

    if let value = snapshot.value as? Dictionary<String,Any> {

        // There is data, so it exists

        print(value)

    } else {

        // There is no data, so it doesn't exist
    }
})

关于ios - 使用 swift 3 在 Firebase 数据库上进行简单搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44400343/

相关文章:

ios - 在 Swift 中转换语法以循环遍历数组数组

ios - 缺少 64 位支持, bundle 无效。提交应用程序时出错

iphone - 预填充的数据库。现在我想添加更多数据而不弄乱预先存在的数据

ios - 如何在 swift ios 中刷新标签栏项目

ios - 工具栏按钮图像被抑制

ios - 使用 NSAttributedString 的 UILabel 的 NSForegroundColorAttributeName

ios - 第一次单击按钮时未显示数据

php - 向数据库记录发送电子邮件时出现 Codeigniter 错误

sql - 自增复合主键

mysql - 如何插入限制为 3 的数据库