Hi I looked through a lot of questions dealing with Firebase's asynchronous database, but no answer quite fixed my problem :
Here is a screenshot of my firebase's structure
Here is a picture of the Output
My for loop prints "BACK TO FALSE" 35 times in a row(number of snapshot.children) BEFORE entering into the if. Is there a way to force the program to wait for the firebase response? Thanks in advance.
ref.child("Events").observe(.value, with: { (snapshot) in
for child in snapshot.children{
multiple = false
print("REMISE A FALSE")
if let result = snapshot.children.allObjects as? [DataSnapshot] {
for child in result {
var eventForClub = child.key as! String
self.ref.child("Events").child("\(eventForClub)").observe(.value, with: { (snapshot) in
for child in snapshot.children{
let snap = child as! DataSnapshot
let event = snap.value as? [String:Any]
let end_time_test = event?["end_time"] as? String
let name_time = event?["name"] as? String
print(end_time_test)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
dateFormatter.timeZone = TimeZone(abbreviation: "GMT+2:00")
let end = dateFormatter.date(from: end_time_test!)!
if(end.compare(self.currentDate!) == .orderedAscending || multiple == true)
{
print("date erronée")
}
else{
print(multiple)
print("GOOD")
multiple = true}