I have a completion block that is returning an Assync array from Firebase, the problem Im having is that the single array is printing each array as it retrieve them I only want to retrieve the final array when it is complete. How can i achieve this?
this is the result being printed
[["lat": 37.33150355, "long": -122.03071596]]
[["lat": 37.33150355, "long": -122.03071596], ["lat": 37.32550194, "long": -122.01974475]]
[["lat": 37.33150355, "long": -122.03071596], ["lat": 37.32550194, "long": -122.01974475], ["lat": 37.332431, "long": -122.030713]]
func dashMapView() {
locationManager.delegate = self
mapView.delegate = self
locationManager.requestAlwaysAuthorization()
mapView.addObserver(self, forKeyPath: "myLocation", options: NSKeyValueObservingOptions.New, context: nil)
var helprInfo = [[String: AnyObject]]()
currentIhelprInfo { (result) in
//helprInfo = result
helprInfo.append(result)
print(helprInfo)
}
}
// get curren Ihelper info
func currentIhelprInfo(completion: (result: [String: AnyObject]) -> ()) {
var userAllInfo: [[String: AnyObject]]!
let dbref = FIRDatabase.database().reference()
dbref.child("users").queryOrderedByChild("receivePostRequest/status").queryEqualToValue(true).observeEventType(.Value, withBlock: { snapshot in
for child in snapshot.children {
let request = child.childSnapshotForPath("receivePostRequest")
var lat = request.value!["lat"] as! Double
var long = request.value!["long"] as! Double
var userInfo = [
"lat": lat,
"long": long
]
//var userArray = userAllInfo.append(userInfo)
completion(result: userInfo)
}
})
}