Hi everyone. This might be a silly question, but I'm new at swift.
I have the following piece of code that I call mapView that loads a map with data from a url json .
so far so good the points get to the map, and the variable doneGettingData does change from false too true when all the points are loaded.
But now I would like to use this variable to set a spinner in my contentView, the issue is that although the variable its available and I can see it changing in the print statement it does not change in the contentView, I have tested with a Text so I could checked it.
Any ideias please ?
Thank you
I have the following piece of code that I call mapView that loads a map with data from a url json .
Code Block import SwiftUI import MapKit import Combine var locationsFillTest : Int = 0 var allLocations = [MKPointAnnotation]() var doneGettingData : Bool = false { didSet { if doneGettingData { print("The instance property doneGettingData is now true.") } else { print("The instance property doneGettingData is now false.") } } } struct MapView: UIViewRepresentable { var startdate : String var depth: String func makeUIView(context: Context) -> MKMapView{ MKMapView(frame: .zero) } func makeCoordinator() -> MapViewCoordinator{ MapViewCoordinator(self) } func updateUIView(_ uiView: MKMapView, context: Context){ uiView.removeAnnotations(allLocations) allLocations = [] doneGettingData = false let url = URL(string: "https://xxxx.com")! URLSession.shared.dataTask(with: url) {(data,response,error) in do { if let d = data { let decodedLists = try JSONDecoder().decode(emsc.self, from: d) DispatchQueue.main.async { locationsFillTest = allLocations.count for locations in decodedLists.features { var mapRegion = MKCoordinateRegion() let mapRegionSpan = 24.0 mapRegion.span.latitudeDelta = mapRegionSpan mapRegion.span.longitudeDelta = mapRegionSpan let lat = Double(locations.properties.lat) let long = Double(locations.properties.lon let annotation = MKPointAnnotation() annotation.coordinate = CLLocationCoordinate2D(latitude: lat , longitude: long ) uiView.addAnnotations(allLocations) uiView.delegate = context.coordinator uiView.showAnnotations(uiView.annotations, animated: true) doneGettingData = true } } catch { print("Error decoding JSON: ", error, response!) } }.resume() } } struct MapView_Previews: PreviewProvider { static var previews: some View { MapView(startdate: "2020-08-23",depth: "All") } }
so far so good the points get to the map, and the variable doneGettingData does change from false too true when all the points are loaded.
But now I would like to use this variable to set a spinner in my contentView, the issue is that although the variable its available and I can see it changing in the print statement it does not change in the contentView, I have tested with a Text so I could checked it.
Any ideias please ?
Thank you