I noticed that AGSQueryTask is no longer available in Quartz. What is the preferred way to query for features on the server? If I create an AGSServiceFeatureTable and then call queryFeaturesWithParameters:completion: method will that run the query against the server or just the features that have been fetched so far?
Solved! Go to Solution.
With swift 3 the code would look like this to do a query against a ServiceFeatureTable. Make sure to hold a reference to the ServiceFeatureTable so that it doesn't go out of scope and get deallocd before the request is finished.
sft = AGSServiceFeatureTable(url: URL(string: "https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/...")!)
sft.featureRequestMode = .onInteractionNoCache
let qp = AGSQueryParameters()
qp.whereClause = "req_type = 'Sidewalk and Curb Issues'"
sft.queryFeatures(with: qp, fields: .loadAll){ result, error in
if let error = error {
print("error querying: \(error)")
}
else{
print("result: \(result)")
let enumerator = result?.featureEnumerator()
while let feature = enumerator?.nextObject(){
print("feature: \(feature)")
}
}
}
The AGSServiceFeatureTable has a property featureRequestMode. If it is set to AGSFeatureRequestModeManualCache then query will happen locally, all other modes query will happen against server.
With swift 3 the code would look like this to do a query against a ServiceFeatureTable. Make sure to hold a reference to the ServiceFeatureTable so that it doesn't go out of scope and get deallocd before the request is finished.
sft = AGSServiceFeatureTable(url: URL(string: "https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/...")!)
sft.featureRequestMode = .onInteractionNoCache
let qp = AGSQueryParameters()
qp.whereClause = "req_type = 'Sidewalk and Curb Issues'"
sft.queryFeatures(with: qp, fields: .loadAll){ result, error in
if let error = error {
print("error querying: \(error)")
}
else{
print("result: \(result)")
let enumerator = result?.featureEnumerator()
while let feature = enumerator?.nextObject(){
print("feature: \(feature)")
}
}
}