I have this swift code:
private func checkPhoneNumber(number: String) -> Bool {
var ret = true
self.db.collection("customers").whereField("telephone", isEqualTo: number).getDocuments(){ (querysnapshot,err) in
if querysnapshot!.documents.count>0{
self.err="This Phone number is already in use"
ret=false
}
}
return ret
}
It sends a request to firebase to check if the phone number is in use. The return value is based on the getDocuments()
function. However, getDocuments()
takes 1-2 seconds to complete, heence checkPhoneNumber
always returns true, before the nested function has time to change the ret
value. I can't do the return ret
inside of getDocuments()
, because it's a different void function. How can I make checkPhoneNumber
wait till the function inside is completed and then return a value?