I have an array of strings and I am trying to populate it through firebase. It is a chat application and when a user creates a room he or she names the room. When the user l
My way is to have the closure. When the call has completed then it will return the number of children
typealias countAllPostsResult = (UInt) -> Void
class func countAllPosts(isDeleted: Bool,completedHandler: @escaping countAllPostsResult) {
print("countAllPosts ...is running...", isDeleted)
var dataSnapshot = [DataSnapshot]()
Constants.Commons.posts_node_ref.queryOrdered(byChild: Constants.Posts.is_deleted).queryStarting(atValue: "false").queryEnding(atValue: "false\u{f8ff}").observeSingleEvent(of: .value, with: { (snapshot) -> Void in
for snap in snapshot.children {
dataSnapshot.append(snap as! DataSnapshot)
}
if dataSnapshot.count > 0 {
completedHandler(UInt(dataSnapshot.count))
} else {
completedHandler(0)
}
})
}