与Swift查询Firebase数据库

发布于 2025-02-13 20:12:58 字数 593 浏览 0 评论 0原文

我正在尝试使用Swift查询Firebase Realtime数据库中的条目?

这是我的代码:

var promoCodes: DatabaseReference {
    return ref.child("PromoCodes")
}


func getIsAffiliate() {
    promoCodes.child("owner").queryEqual(toValue: 33206).observeSingleEvent(of: .value) { snapshot in
        print("SNAP HERE: \(snapshot)")
        AffiliateService.isAffiliate = snapshot == nil
    }
}

输出:snap在此处:snap(lander)< null>

“输入图像在这里说明“

I am trying to query an entry in my firebase realtime database with Swift to basically see if an entry exists with the owner = 33206. My current code is not returning what I need, how can I fix this query?

Here is my code:

var promoCodes: DatabaseReference {
    return ref.child("PromoCodes")
}


func getIsAffiliate() {
    promoCodes.child("owner").queryEqual(toValue: 33206).observeSingleEvent(of: .value) { snapshot in
        print("SNAP HERE: \(snapshot)")
        AffiliateService.isAffiliate = snapshot == nil
    }
}

Output: SNAP HERE: Snap (owner) <null>

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

躲猫猫 2025-02-20 20:12:58

快照传递给代码的永远不会是nil。要检查是否有匹配的节点,您可以检查 snapshot.exists() 而不是。

The snapshot passed to your code will never be nil. To check if there are matching nodes, you can check snapshot.exists() instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文