<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Crash when supplying graphicsOverlays for MapView in latest SwiftUI SDK in Swift Maps SDK Questions</title>
    <link>https://community.esri.com/t5/swift-maps-sdk-questions/crash-when-supplying-graphicsoverlays-for-mapview/m-p/1375635#M199</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/739794"&gt;@dmc76&lt;/a&gt;,&amp;nbsp;this issue is still being investigated. In the meantime a potential workaround would be to wrap the &lt;FONT face="courier new,courier"&gt;MapView&lt;/FONT&gt; within a &lt;FONT face="courier new,courier"&gt;VStack&lt;/FONT&gt;.&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;NavigationStack {
    VStack {
        MapView(…)
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
    <pubDate>Mon, 29 Jan 2024 20:16:17 GMT</pubDate>
    <dc:creator>DavidFeinzimer</dc:creator>
    <dc:date>2024-01-29T20:16:17Z</dc:date>
    <item>
      <title>Crash when supplying graphicsOverlays for MapView in latest SwiftUI SDK</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/crash-when-supplying-graphicsoverlays-for-mapview/m-p/1350620#M160</link>
      <description>&lt;P&gt;First off, this is my first Swift project, because I'm forced to use Swift, because your SDK doesn't support Objective-C.&lt;/P&gt;&lt;P&gt;I have a project that started out as the boilerplate "New Swift Project" in Xcode.&amp;nbsp; I have a ContentView that contains a MapView.&amp;nbsp; The MapView's .task loads an MMPK file that is downloaded onto the device if it isn't present already.&amp;nbsp; This is all working just fine.&lt;/P&gt;&lt;P&gt;However - if I specify the graphicsOverlays: parameter for the MapView (again, this is basically copied code verbatim from your tutorials - with the Model class, etc.), I get the following runtime crash:&lt;/P&gt;&lt;P&gt;/Users/jenkins/workspace/200.2.0/daily_swift_SDK_release/swift/ArcGIS/Sources/ArcGIS/Common/CoreMutableArray.swift:47: Fatal error: Object is already in use and may not be reused.&lt;/P&gt;&lt;P&gt;I have tried to create the GraphicsOverlay in every which way - with your "pierLocation" point, with no points, with GPS coordinates that match the MMPK file I've loaded.&amp;nbsp; Nothing will get me past that error.&amp;nbsp; There just doesn't seem to be anything else I can do, there's barely any code in this project and the parts that matter are straight out of the tutorial.&amp;nbsp; Any ideas?&amp;nbsp; I'm just trying to put a dot on a map at my current coordinate.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2023 01:53:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/crash-when-supplying-graphicsoverlays-for-mapview/m-p/1350620#M160</guid>
      <dc:creator>dmc76</dc:creator>
      <dc:date>2023-11-17T01:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: Crash when supplying graphicsOverlays for MapView in latest SwiftUI SDK</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/crash-when-supplying-graphicsoverlays-for-mapview/m-p/1350630#M161</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/739794"&gt;@dmc76&lt;/a&gt;, thank you for reaching out! I'd like to help you troubleshoot your problem. If possible, would you be able to post the portion of your code that will trigger the crash? Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In the meantime, I'd like to point you to our &lt;A href="https://github.com/Esri/arcgis-maps-sdk-swift-samples/tree/main/Shared/Samples/Show%20device%20location" target="_blank" rel="noopener"&gt;Show device location&lt;/A&gt; sample which contains complete code for your indicated use case.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2023 03:35:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/crash-when-supplying-graphicsoverlays-for-mapview/m-p/1350630#M161</guid>
      <dc:creator>DavidFeinzimer</dc:creator>
      <dc:date>2023-11-17T03:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: Crash when supplying graphicsOverlays for MapView in latest SwiftUI SDK</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/crash-when-supplying-graphicsoverlays-for-mapview/m-p/1350955#M162</link>
      <description>&lt;P&gt;So, I have tracked down the issue, but I have no idea why it's happening.&amp;nbsp; I combined two sample/tutorial items, the GraphicsOverlay example and an example I found to manage layers.&amp;nbsp; When I first tried this sample, the toolbar was not showing and the Internet told me I needed to have a NavigationStack.&amp;nbsp; After I put that in there, the toolbar started working.&amp;nbsp; Then I added the GraphicsOverlay to the MapView and the crash happened.&amp;nbsp; I stripped back all the code this morning to find the issue was having the MapView inside of a NavigationStack.&amp;nbsp; I have since removed the NavigationStack and the .toolbar still works, so I'm not sure why it wasn't working before or why the NavigationStack caused it to work.&amp;nbsp; Here's an example (with the GraphicsOverlay param on the MapView commented out, uncomment to get the crash).&amp;nbsp; Again, I have never used SwiftUI before, so maybe there's some reasonable explanation why a MapView with a GraphicsOverlay can't live inside of a NavigationStack.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;//
//  ContentView.swift
//

import SwiftUI
import ArcGIS

private class Model: ObservableObject {
    let map: Map = {
        let map = Map(basemapStyle: .arcGISTopographic)
        map.initialViewpoint = Viewpoint(latitude: 34.027, longitude: -118.805, scale: 72_000)
        return map
    }()

    let graphicsOverlay: GraphicsOverlay = {
        // Create a graphics overlay.
        let overlay = GraphicsOverlay()

        // Create a point for the graphic location.
        let pierLocation = Point(x: -118.4978, y: 34.0086, spatialReference: .wgs84)

        // Create a red circle symbol.
        let redCircleSymbol = SimpleMarkerSymbol(style: .circle, color: .red, size: 10)

        // Create a graphic using the point and the symbol.
        let pierGraphic = Graphic(geometry: pierLocation, symbol: redCircleSymbol)

        // Add the graphic to the graphics overlay.
        overlay.addGraphic(pierGraphic)

        return overlay
    }()
}

struct ContentView: View {
    @Environment(\.managedObjectContext) private var viewContext

	@StateObject private var model = Model()
	@State private var isShowingSheet = false

    var body: some View	{
		NavigationStack
		{
			MapView(map: model.map)//, graphicsOverlays: [model.graphicsOverlay])
			.toolbar
			{
				ToolbarItem(placement: .bottomBar)
				{
					Button("Manage Layers")
					{
						self.isShowingSheet = true
					}
					.sheet(isPresented: $isShowingSheet)
					{
						ManageLayersSheetView(map: self.model.map)
					}
					.presentationDetents([.medium] )
					.presentationDragIndicator(.visible )
				}
			}
		}
    }
}

struct ManageLayersSheetView: View {
	/// The map with the operational layers.
	let map: Map

	/// The action to dismiss the manage layers sheet.
	@Environment(\.dismiss) private var dismiss

	/// An array for all the layers currently on the map.
	@State private var operationalLayers: [Layer] = []

	/// An array for all the layers removed from the map.
	@State private var removedLayers: [Layer] = []

	var body: some View {
		VStack {
			ZStack {
				Text("Manage Layers")
					.bold()
				HStack {
					Spacer()
					EditButton()
				}
			}
			.padding([.top, .leading, .trailing])

			List {
				Section {
					ForEach(operationalLayers, id: \.id) { layer in
						HStack {
							Image(systemName: "minus.circle.fill")
								.foregroundColor(.red)
								.imageScale(.large)
								.clipped()
								.onTapGesture {
									// Remove layer from map on minus press.
									map.removeOperationalLayer(layer)
									removedLayers.append(layer)
									operationalLayers.removeAll(where: { $0.id == layer.id })
								}
							Text(layer.name)
						}
					}
					.onMove { fromOffsets, toOffset in
						// Reorder the map's operational layers on list row move.
						operationalLayers.move(fromOffsets: fromOffsets, toOffset: toOffset)
						map.removeAllOperationalLayers()
						map.addOperationalLayers(operationalLayers)
					}
				} header: {
					Text("Operational Layers")
						#if targetEnvironment(macCatalyst)
						.padding(.top)
						#endif
				} footer: {
					Text("Tap \"Edit\" to reorder the layers.")
				}

				Section {
					ForEach(removedLayers, id: \.id) { layer in
						HStack {
							Image(systemName: "plus.circle.fill")
								.foregroundColor(.green)
								.imageScale(.large)
								.clipped()
								.onTapGesture {
									// Add layer to map on plus press.
									map.addOperationalLayer(layer)
									operationalLayers.append(layer)
									removedLayers.removeAll(where: { $0.id == layer.id })
								}
							Text(layer.name)
						}
					}
				} header: {
					Text("Removed Layers")
				}
			}
		}
		.background(Color(.systemGroupedBackground))
		.onAppear {
			operationalLayers = map.operationalLayers
		}
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2023 17:22:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/crash-when-supplying-graphicsoverlays-for-mapview/m-p/1350955#M162</guid>
      <dc:creator>dmc76</dc:creator>
      <dc:date>2023-11-17T17:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: Crash when supplying graphicsOverlays for MapView in latest SwiftUI SDK</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/crash-when-supplying-graphicsoverlays-for-mapview/m-p/1351190#M166</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/739794"&gt;@dmc76&lt;/a&gt;, when running your code above (first un-commenting the MapView's graphics overlay parameter) I was unable to reproduce any warnings or crashes. Were there any additional steps needed to trigger the crash or does it happen&amp;nbsp;for you as soon as the view loads? Is there possibly any more code that was accidentally left out? Thank you.&lt;/P&gt;</description>
      <pubDate>Sat, 18 Nov 2023 02:50:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/crash-when-supplying-graphicsoverlays-for-mapview/m-p/1351190#M166</guid>
      <dc:creator>DavidFeinzimer</dc:creator>
      <dc:date>2023-11-18T02:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: Crash when supplying graphicsOverlays for MapView in latest SwiftUI SDK</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/crash-when-supplying-graphicsoverlays-for-mapview/m-p/1351769#M167</link>
      <description>&lt;P&gt;No, that's the entirety of the ContentView.swift file.. the rest of the project is just the boilerplate "new project" stuff from Xcode (the PersistenceController class, etc).&amp;nbsp; I replaced the swift file I've been working on with what I posted here on the forum and it still crashes when uncommenting the graphicsOverlays param.&amp;nbsp; Very strange that it's not happening for you too.&amp;nbsp; I'm on Xcode 14.3.1 for what it's worth.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2023 00:16:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/crash-when-supplying-graphicsoverlays-for-mapview/m-p/1351769#M167</guid>
      <dc:creator>dmc76</dc:creator>
      <dc:date>2023-11-21T00:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: Crash when supplying graphicsOverlays for MapView in latest SwiftUI SDK</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/crash-when-supplying-graphicsoverlays-for-mapview/m-p/1352268#M172</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/739794"&gt;@dmc76&lt;/a&gt;, while it's not the greatest answer, testing the exact same code on in Xcode 14.3.1 with an iOS 16.4 simulator crashes while everything runs fine in Xcode 15.0 with an iOS 17.0 simulator. This would explain why I couldn't reproduce this at first as I was testing with only the latter beforehand.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To the best of my knowledge there shouldn't be any issue placing a MapView within a NavigationStack so if I find out any other info or known workarounds for this scenario in iOS 16.x I'll make sure to update you in this thread.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Swift Known Issue #4281&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2023 21:50:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/crash-when-supplying-graphicsoverlays-for-mapview/m-p/1352268#M172</guid>
      <dc:creator>DavidFeinzimer</dc:creator>
      <dc:date>2023-11-21T21:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: Crash when supplying graphicsOverlays for MapView in latest SwiftUI SDK</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/crash-when-supplying-graphicsoverlays-for-mapview/m-p/1375635#M199</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/739794"&gt;@dmc76&lt;/a&gt;,&amp;nbsp;this issue is still being investigated. In the meantime a potential workaround would be to wrap the &lt;FONT face="courier new,courier"&gt;MapView&lt;/FONT&gt; within a &lt;FONT face="courier new,courier"&gt;VStack&lt;/FONT&gt;.&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;NavigationStack {
    VStack {
        MapView(…)
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2024 20:16:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/crash-when-supplying-graphicsoverlays-for-mapview/m-p/1375635#M199</guid>
      <dc:creator>DavidFeinzimer</dc:creator>
      <dc:date>2024-01-29T20:16:17Z</dc:date>
    </item>
    <item>
      <title>Re: Crash when supplying graphicsOverlays for MapView in latest SwiftUI SDK</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/crash-when-supplying-graphicsoverlays-for-mapview/m-p/1379587#M206</link>
      <description>&lt;P&gt;FYI:&lt;BR /&gt;&lt;BR /&gt;I faced the same issue, and it only fixed it for me by removing it from the NavigationStack + I had to set the graphicsOverlayProperty from this:&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&lt;STRONG&gt;let&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN class=""&gt;routeGraphicsOverlay&lt;/SPAN&gt; = GraphicsOverlay()&lt;BR /&gt;&lt;BR /&gt;To This:&amp;nbsp;&lt;BR /&gt;&lt;SPAN class=""&gt;&lt;STRONG&gt;let&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN class=""&gt;routeGraphicsOverlay: [GraphicsOverlay]&lt;/SPAN&gt; = [.init()]&lt;BR /&gt;&lt;BR /&gt;Because passing the graphicsOverlay to the MapView like this also crashes the App also without NavigationStack:&lt;BR /&gt;MapView(map: model.map, graphicsOverlay: [model.graphicsOverlay])&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2024 10:11:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/crash-when-supplying-graphicsoverlays-for-mapview/m-p/1379587#M206</guid>
      <dc:creator>JessevanderVoorn</dc:creator>
      <dc:date>2024-02-08T10:11:52Z</dc:date>
    </item>
  </channel>
</rss>

