0
我有一個完成塊,從Firebase返回一個Assync數組,我遇到的問題是單個數組打印每個數組,因爲它檢索它們我只想檢索最終數組當它完成時。我怎樣才能做到這一點?swift從一個完成塊獲得最終數組
這是正在打印
[["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)
}
})
}