I have a function must return a string, but my problem is Asynchronous Tasks. How to wait and get results out completion of featureTable.queryFeatures. Thanks! func GetValueSum(geo : AGSGeometry ) -> String{
var strReturn = ""
let queryParameters = AGSQueryParameters()
queryParameters.geometry = geo
queryParameters.spatialRelationship = AGSSpatialRelationship.intersects
queryParameters.outSpatialReference = self.mapView.spatialReference
self.featureTable?.queryFeatures(with: queryParameters, completion: { (result: AGSFeatureQueryResult?, error: Error?) in
if error != nil {
print("Error in function")
} else if let features = result?.featureEnumerator().allObjects {
for feature in features {
strReturn += "\(feature.attributes["Label1"]!); "
print("For string: \(strReturn)")
}
}
})
print("Return string: \(strReturn)")
return strReturn
} The result: But the "Return string" must be the last "For string". Thanks for help!
... View more