0

I am trying to find out a way to handle no data in the DB state (zero state).

My code is:

Database.database()
    .reference(withPath: "My_Path")
    .child("My_Inner_Path")
    .observeSingleEvent(of: .value) { (snapshot) in
        // Callback with data at the observing node.
}

But the above code doesn't get called back if the node is empty, or doesn't exist yet. I need to do this so that I can hide my indicator and show zero state or trigger some other methods for no data at node state. Thanks in advance.

Lazy
  • 670
  • 5
  • 14

1 Answers1

0

Following is the solution to my problem in Swift.

Database.database()
.reference(withPath: "My_Path")
.child("My_Inner_Path")
.observeSingleEvent(of: .value) { (snapshot) in
    guard snapshot.exists() else {
        // The node doesn't exist.
        return
    }
    // OR
    guard snapshot.childrenCount != 0 else {
        // No children exist.
        return
    }    
}
Lazy
  • 670
  • 5
  • 14