I'm trying to set a variable to a boolean based on this code here:
Firestore.firestore().collection("users").whereField("username", isEqualTo: usernameTextField.text!).getDocuments
{ (querySnapshot, error) in
if let error = error { print(error.localizedDescription) /*ALERT*/ }
else
{
if querySnapshot!.isEmpty
{
print("QuerySnapshot is empty, this is unique")
retVal = true
}
else
{
print("There's a bloody username in here, get a new one")
retVal = false
}
}
}
return retVal
The issue is however, retVal is not changed. I understand what's going on here, it's an asynchronous block of code, however I don't understand how to fix it or work around it to fit my needs. How do I get the value of retVal, (or honestly just return true or false within this block of code) despite it being asynchronous. Is there anyway I can like wait for it to finish before further execution of code?