Swift上的Firebase,如果查询是空的,如何得到通知? [英] Firebase on Swift, how to get notified if a query is empty?
问题描述
您好我在swift中使用firebase,我试图通过用户名搜索用户名,如下所示:
<$ c $ queryEqualToValue(firstTextField.text)
.observeEventType(.ChildAdded,withBlock:{snapshot in
这个工作很好,但是我想在查询是空的时候被通知,也就是说没有用户拥有这个用户名。我如何编辑我如何格式化我的搜索,以允许这样做?谢谢!
编辑:
我的树看起来像这样:
用户:{
pre>
asdfasdfkl:{
用户名:bob,
高分:1000
}
}
将事件类型更改为.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屋!