Here is a method that toggles the state of a boolean variable called imageryOn.
When I tap a button the code runs, and I am able to set the first object in the Operational Layers array as a ArcGISTiledLayer. Cool, tapping the on screen button shows the satellite imagery hosted service on the map and sets it to Operational Layers at index 0.
When I toggle the imageryOn bool to false I get an error message when trying to remove the first operational layer:
Thread 1: Fatal error: Object is already in use and may not be reused.
However, if I used the removeAllOperationalLayers method I am able to remove all operational layers (including the imagery layer). And the toggle then just shows imagery on and then imagery off.
func toggleImagery(){
imageryOn = !imageryOn
print(map.operationalLayers)
if imageryOn {
let imageryLayer = ArcGISTiledLayer(url: URL(string: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer")!)
map.insertOperationalLayer(imageryLayer, at: 0)
print(map.operationalLayers.first!)
print(map.operationalLayers)
} else {
map.removeOperationalLayer(map.operationalLayers[0])
//map.removeAllOperationalLayers()
}
}
Any ideas on what could be going on here?
Thanks
Solved! Go to Solution.
I face a similar issue, when in a navigation stack I navigate back to my config screen from the Map screen, I get this fatal error. Strangely when I have my Map component in our UIKit framework , it works fine. I get this error only in our test application which is built with SwiftUI.
Were you able to solve this?
There were multiple issues in the past few releases regarding NavigationStack, the operational layer array insertion bug, and iOS 15/16/17 navigation behavior differences. Some of the problem we were able to resolve on our end, some were addressed by Apple in iOS 17, and some are temporarily fixed with patches. If possible, can you adopt 200.4.0 or 200.5.0 version of the SDK to see if the problems are addressed? If not, feel free to open a new question and we can look further into it.