【发布时间】:2016-08-16 05:56:28
【问题描述】:
我有一个执行闭包的函数。
func callWebServiceToFindLocation(limitedClLocations: [CLLocation]) {
// self.view.showLoaderWithMessage(FRDMessageConstants.pleaseWaitWhilecollectingGPSCoordinates)
FRDRouteDirectionServices.getRoutesWithLocations(limitedClLocations, travelMode: TravelMode.TravelModeWalking, completitionBlock: { (routes) in
// self.routes.arrayByAddingObject(routes)
// print("\(self.routes.count)")
FRDMapUtilities.sharedInstance.plotPolyLineOnMap(routes as! NSArray, viewMap: self.viewMap)
FRDMapUtilities.sharedInstance.addMarkerAndSetAllMarkerBoundToScreen(self.clLocations, viewMap: self.viewMap, allStoreDetails: self.allStoreDetailsForMarker, myLocaion: self.myLocation)
self.view.hideLoader()
}, andErrorBlock: { (error) in
self.showRefreshButton()
self.view.hideLoader()
})
}
由于某些原因,现在这个函数将被调用两次callWebServiceToFindLocation(),然后我只需要调用一次plotPolyLineOnMap,因此我附加了FRDRouteDirectionServices.getRoutesWithLocations(limitedClLocations, travelMode: TravelMode.TravelModeWalking, completitionBlock: { (routes) in中返回的路由
到一个全局数组中。
现在我知道闭包的执行是异步进行的。我怎样才能为路由的全局数组只调用一次plotPolyLineOnMap。
【问题讨论】: