I have a function bellow called retrieveUsers()
which is called inside a function which fetches all posts under a Post node.
Inside the code found bellow I save the current UID to a variable with global scope. But every time this function gets called the variable (lastUID) seems to be reset. Even though this method is being called in a for-loop essentially.
func retrieveUsers(value: Post) {
print(lastUID, "-=-=--=-=")
print(value.user.userID != lastUID, ": ", value.user.userID!, " email left old ... one -> ", lastUID)
if value.user.userID != lastUID {//Ignore this line
let ref = Database.database().reference()
if value.user.userID != nil {
let UID = value.user.userID!
print(UID, "Thoi s is the uid in the users fetch fx")
ref.child("users2").child(UID).observe(.value, with: { (snapshot) in
let email = "\(snapshot.childSnapshot(forPath: "email").value as! String)"
do {
value.user.email = email
//even with the two values being in here the same thing happens
}
self.lastUID = UID
self.lastEmail = email
})
}
} else {
print("ESC this is the same user")
value.user.email = lastEmail
}
}
What is going wrong?