pprevalon pprevalon - 5 months ago 50
iOS Question

How can i access variables inside of firebase .ref closures and use them outside

I declared a variable inside a firebase function i would like to use it outside of the function. I already declare the variable outside of the function and then set it inside of the firebase function but Im still not able to retrieve how can i process this.

let ref = firebasehelper.firebaseURL()
var userDict = [String:String]()
var name:String!

override func viewDidLoad() {

ref.childByAppendingPath("backend/posts").queryOrderedByChild("jobOfferFromId").queryEqualToValue(ref.authData.uid).observeEventType(.ChildAdded, withBlock: {snapshot in

self.name = snapshot.value["jobDescribe"] as! String

// work greate in here


// does not work outside of the Firebase function I want to access the data out here



Create a func inside the class then place the func inside the class this will allow you to set that variable inside the funciton