I need to create calendar that displays data downloaded from three/four different documents from Firestore. I need to fill the array with that data and then display it. The code below shows how I'm dealing with three functions with escaping block. One is triggered after another.
func getUserOrders(startDate: Timestamp, endDate: Timestamp){
guard let userID = Auth.auth().currentUser?.uid else {return}
orderBrain.returnWhenSomeneOrderedUser(userID: userID, startDate: startDate, endDate: endDate) { (calendar1) in
self.orderBrain.returnWhenUserBoughtOrders(userID: userID, startDate: startDate, endDate: endDate) { (calendar2) in
self.orderBrain.getOrdersFromArchive(userID: userID, startDate: startDate, endDate: endDate) { (calendar3) in
self.fillEvents(event1: calendar1, event2: calendar2, event3: calendar3)
}
}
}
}
After the last is completed I'm added downloaded values to an array.
func fillEvents(event1: [CalendarEvent], event2: [CalendarEvent], event3: [CalendarEvent] ){
self.models = event1 + event2 + event3
self.reloadData()
}
The above code works but I'm wondering if there is a better more elegant solution when downloading data and filling an array from more than one escaping function. The problem with above code is that when sometimes it doesn't update data from Firestore (when user changes for ex. date)
Thank you Matt