lundi 17 octobre 2016

Swift 2.2 - value is not persisted after function execution

I created the function above to check if a user exists on Firebase database:

func userExists(userUid: String) -> Bool {
    var userExists: Bool = false
    DBRef.child("users").child(userUid).observeSingleEventOfType(.Value, withBlock: { (snapshot: FIRDataSnapshot) in
        if snapshot.exists(){
            userExists = true
        }else{
            userExists = false
        }
    })
    return userExists
}

The problem is that the userExists function always returns "false", even if the userExists variable is setted as true inside the withBlock. Any help, please? Thanks!

Aucun commentaire:

Enregistrer un commentaire