Reputation: 413
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
Upvotes: 1
Views: 883
Reputation: 83
for Swift 5.0, it's been updated to if (querySnapshot?.isEmpty == true) {}
Upvotes: 0
Reputation: 1255
you can check if the snapshot exist, this will return a Bool
snapshot.exists()
Upvotes: 1