So I want a Boolean function that returns true or false depending on whether the given email exists for a user in the users collection.
However if I try and return True or False within the getDocuments call I get the error: non-void return value in void function
func checkUserWith(email: String) -> Bool
{
let usersDB = database.collection("users")
usersDB.whereField("email", isEqualTo: email).getDocuments { (snapshot, error) in
if error != nil
{
print("Error: \(error?.localizedDescription ?? "")")
return false
}
for document in (snapshot?.documents)! {
if document.data()["email"]! as! String == email {
return true
}
}
return false
}
}
I have a feeling it is because I am trying to return a boolean within the Firestore call which is expecting a different variable type?