Swift上的Firebase,如果查询是空的,如何得到通知? [英] Firebase on Swift, how to get notified if a query is empty?

查看:82
本文介绍了Swift上的Firebase,如果查询是空的,如何得到通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我在swift中使用firebase,我试图通过用户名搜索用户名,如下所示:

 <$ c $ queryEqualToValue(firstTextField.text)
.observeEventType(.ChildAdded,withBlock:{snapshot in

这个工作很好,但是我想在查询是空的时候被通知,也就是说没有用户拥有这个用户名。我如何编辑我如何格式化我的搜索,以允许这样做?谢谢!

编辑:

我的树看起来像这样:

 用户:{

asdfasdfkl:{

用户名:bob,

高分:1000

}

}
pre>

将事件类型更改为.Value时,使用snapshot.value时,我不再获得adjkadfjla ID。 b $ b

解决方案

您可以检查是否t他的快照存在,这将返回一个布尔

  snapshot.exists()


Hello I am using firebase in swift and I am trying to search through my users by user name using a query like so:

InfoCenter.ref.child("users").queryOrderedByChild("username").queryEqualToValue(firstTextField.text)
            .observeEventType(.ChildAdded, withBlock: { snapshot in

This works great but I want to be notified if the query is empty aka the there is no user that has that user name. Can someone please show me how to edit how I format my search to allow for that? Thanks!

Edit:

My tree looks like this:

users:{

asdfasdfkl:{

username: "bob",

highscore: "1000"

}

}

upon changing event type to .Value, when using snapshot.value I no longer get the adjkadfjla ID. I now get the entire try below it

解决方案

you can check if the snapshot exist, this will return a Bool

snapshot.exists()

这篇关于Swift上的Firebase,如果查询是空的,如何得到通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆