This might have been asked here but I couldn't find a solution.
I'm making a search function and if a user puts an email matched in the firebase database, I want to change the value of the result checking variable(checkResult) below.
I know how it doesn't work, but I can't find a solution.
guard let emailSearch = searchBar.text else { return }
var checkResult = false
let ref = Database.database().reference()
ref.child("users").observe(.childAdded, with: { (snapshot) in
guard let dictionary = snapshot.value as? [String: Any] else { return }
let user = User(dictionary: dictionary)
if user.email == emailSearch {
checkResult = true
}
}) { (err) in
print("Error: ", err)
}
print(checkResult)