我正在尝试找出一种在DB状态(零状态)下不处理任何数据的方法。
我的代码是:
Database.database()
.reference(withPath: "My_Path")
.child("My_Inner_Path")
.observeSingleEvent(of: .value) { (snapshot) in
// Callback with data at the observing node.
}
但是,如果节点为空或尚不存在,则上述代码不会被回调。我需要这样做,以便可以隐藏我的指示器并显示零状态,或在节点状态下触发一些其他方法以无数据。预先感谢。
答案 0 :(得分:0)
以下是我在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
}
}