IPhone : NSMutableArray doesn't save Objects out side .observeEventType from Firebase api

on Thursday, April 9, 2015

Now my project is using https://www.firebase.com as backend for swift app. And i tried to addObject to my NSMutableArray variable in order to use it for my tablecell.


So i can Retrieving Data correctly inside . observeEventType() from their Api but outside that my NSMutableArray always empty here is my code


// Create a reference to a Firebase location



var bidRef = Firebase(url:"https://xxxx.firebaseio.com/xxx")

println("firebase test")

// Read data and react to changes
var handle = bidRef.queryOrderedByChild("tableCurrentPrice").observeEventType(.ChildAdded, withBlock: { snapshot in

self.pubDataArray.addObject(snapshot.value)
println(self.pubDataArray[0]["tableCurrentPrice"]) //Return Optional(Value)

}, withCancelBlock: { error in
println(error.description)
})

//bidRef.removeObserverWithHandle(handle)

println(self.pubDataArray[0]["tableCurrentPrice"]) // Error empty array
println(self.pubDataArray.count) // Return Nothing


Anyone knows how to fix this? Thanks!


0 comments:

Post a Comment