I'm trying to return a bool value from the function but I can't, I've tried many options, it always returns false. Does anyone know where the problem is?
func checkBusyDates(busyDate: Date) -> Bool {
let db = Firestore.firestore()
var busyResult: Bool = true
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "y-MM-dd"
let eventDate = dateFormatter.string(from: busyDate)
db.collection("book").whereField("eventDate", isEqualTo: eventDate).getDocuments { snapshot, error in
if error != nil {
print("Document Error: ", error!)
} else {
if let doc = snapshot?.documents, !doc.isEmpty {
busyResult = true
print("Date is busy.")
}
else {
busyResult = false
print("Date is not busy.")
}
}
}
return busyResult
}