T Neate T Neate - 4 months ago 45
Swift Question

Firebase on Swift, how to get notified if a query is empty?

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

Answer

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

snapshot.exists()
Comments