I'm building a specific database (picture below) and I want to display the results in the labels. The first label should show the number of all customers - it's simple, but the second label should show the number of all the child's clients, for example: if the customer Ben has one child, and Tom has one child - label shows 2 (number of child's clients).
Is possible to do this?
My code:
let userID = Auth.auth().currentUser!.uid
ref.observeSingleEvent(of: .value, with: { snapshot in
if let allServices = snapshot.childSnapshot(forPath: "usersDatabase/(userID)/Customers").value {
if snapshot.childrenCount == 0 {
self.servicesLabel.text = "0"
} else {
self.servicesLabel.text = (allServices as AnyObject).count.description
}
}