与Swift查询Firebase数据库
我正在尝试使用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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
快照
传递给代码的永远不会是nil
。要检查是否有匹配的节点,您可以检查snapshot.exists()
而不是。The
snapshot
passed to your code will never benil
. To check if there are matching nodes, you can checksnapshot.exists()
instead.