I'm using Firebase (Swift) to read a list of group ids that the user belongs to then looping over the ids to get more info about the groups. Something similar to this (pseudo code):
// List the names of all Mary's groups
var ref = new Firebase("https://docs-examples.firebaseio.com/web/org");
// fetch a list of Mary's groups
ref.child("users/mchen/groups").on('child_added', function(snapshot) {
// for each group, fetch the name and print it
String groupKey = snapshot.key();
ref.child("groups/" + groupKey + "/name").once('value', function(snapshot) {
System.out.println("Mary is a member of this group: " + snapshot.val());
});
});
How do I know that all Firebase observeSingleEvent
has done executing so I could reload the data in my collection view.
Edit:
After doing more research, this looks very similar to this question. I could use dispatch_group
or Bolts framework
Edit 2:
Thanks to @appzYourLife for his answer. I also was able to solve it using RxSwift
. I simply wrapped the Firebase calls with observers and saved them in an array then called
Observable.zip(observables, { _ in }).subscribe(onCompleted: {
self.contentView.collection.reloadData() // do something here
})