I have the following function that observes values of my database's child node:
func findUser() {
let tempUser = "jordan"
let firRef = FIRDatabase.database().reference()
let userRef = firRef.child("user-referances")
var username:String?
userRef.observe(.value, with: { (snapshot) in
if let dictionary = snapshot.value as? [String:AnyObject] {
print(snapshot)
print(dictionary)
username = dictionary["username"] as? String
//print("usernam)
if username == tempUser {
print("username exists")
print(username)
//return
}else {
print("username not found")
}
}
}) { (error) in
print(error)
}
}
When I try to assign dictionary value to a string and compare them, it does not assign it. However when i print dictionary values, the values are there.