I'm trying to return a list of booleans to check in what registration step the user is and if it has registered through Facebook or Phone. The function I made gets the user doc and checks for two fields to see if they exist (interest and id). id, because only FB users have that field and interests because that is the last step of the registration process. It appears the function is returning the default values [true,true] before I even get the chance to modify the values.
fileprivate func checkRegistrationComplete(_ uid: String?) -> [Bool] {
//I will return a list with the first bool to know if it has filled all the info and the second if it has done so through FB or phone
var userRegistered = true
var userRegisteredFB = true
let db = Firestore.firestore()
let docRef = db.collection("users").document(uid!)
docRef.getDocument { (document, error) in
if let document = document, document.exists {
let dataDescription = document.data()
userRegistered = dataDescription?["interest"] != nil
userRegisteredFB = dataDescription?["id"] != nil
print(userRegisteredFB)
print(userRegistered)
} else {
print("Document does not exist")
}
}
print(userRegisteredFB,userRegistered)
return [userRegistered,userRegisteredFB]
}
The output should be [false,true] but it returns [true,true]. And the print functions show that the get method is actually working but it shows after the return call