Below is my code. I am not getting any response, neither success nor any failure. URL for FeatureServer is my organisations's FeatureServer Url.
self.pointFeatureTable = AGSServiceFeatureTable(url: URL(string: url)!)
let point:AGSPoint = AGSPoint(clLocationCoordinate2D: CLLocationCoordinate2D(latitude: 32.7157, longitude: 117.1611))
self.pointFeatureTable.credential = MyAGSHelper.sharedInstance().getCredentials();
self.pointFeatureTable.load { (error:Error?) in
if let error = error {
print(error.localizedDescription)
}
else{
let feature:AGSFeature = self.pointFeatureTable.createFeature(attributes: ["test":"test"], geometry: point)
self.pointFeatureTable.add(feature) { (error: Error?) -> Void in
if let error = error {
print("Error while adding feature :: \(error.localizedDescription)")
return
}
else{
self.pointFeatureTable.applyEdits { (result, error) in
if let error = error {
print("Error while adding feature :: \(error.localizedDescription)")
return
}
else{
print(result!)
}
}
}
}
}
}
Please help and let me know it there is any mistake. !
Solved! Go to Solution.
As soon as your pointFeatureTable variable goes out of scope it'll be deallocated, and so there's nothing left to call back into your callback blocks. Try creating a class-level variable to keep your pointFeatureTable reference in, or derive it from a layer in the map (the map will keep a layer reference, and the layer will keep a table reference).
See this sample, where the featureTable variable is defined at the class level, so will exist as long as the owning class does.
As soon as your pointFeatureTable variable goes out of scope it'll be deallocated, and so there's nothing left to call back into your callback blocks. Try creating a class-level variable to keep your pointFeatureTable reference in, or derive it from a layer in the map (the map will keep a layer reference, and the layer will keep a table reference).
See this sample, where the featureTable variable is defined at the class level, so will exist as long as the owning class does.
As you can see in my code it is self.pointFeatureTable, so it is already a class variable.
In my class I have declared it as:
private var pointFeatureTable:AGSServiceFeatureTable!
Oh yes, I'm sorry. I missed the "self".
You could do a couple of things to dig in.
AGSRequestConfiguration.global().debugLogRequests = true
AGSRequestConfiguration.global().debugLogResponses = true
Let me know what you find.
Hey @Nicholas! Thanks for the help. Actually your first solution worked with some modifications, I declared and initialized the pointFeatureTable at the class level itself, and it resolved my issue. Earlier I only declared the variable at class level, not initialized at class level.
Working code:
class MyClass{
lazy var pointFeatureTable:AGSServiceFeatureTable = AGSServiceFeatureTable(url: URL(string: myURL)!)
func myFunc(){
//rest of the above mentioned code
}
}
Glad it working for you, but that's odd. It shouldn't matter. I just tried to reproduce this with your original code and it adds features fine.
Could you have made some other edit to the code in the meantime? Can you try setting self.pointFeatureLayer as in your original code again just as a sanity check?