My project is using https://www.firebase.com as backend for a Swift app.
I tried to addObject
to my NSMutableArray
variable in order to use it for my table cell.
So I can retrieve data correctly inside .observeEventType()
from the Firebase 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?