0

I was trying to figure out how to get rid of a lot of warning on my council and I came to the conclusion that these warnings happens just after I add overlays to my mapKit

here's the part where I add the overlays..

    let FireLocation = CLLocationCoordinate2D(latitude: 40.836352, longitude: 14.306019)
    let CircularRegion = CLCircularRegion(center: FireLocation, radius: 500, identifier: "fire")
    CircularRegion.notifyOnEntry = true
    CircularRegion.notifyOnExit = true
    self.locatManager.startMonitoring(for: CircularRegion)

     let geo = MKCircle(center: FireLocation, radius: CircularRegion.radius)
     mapkitView.addOverlay(geo)

after that I customize these overlays on the delegate method...

  func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {

        guard let circularOverlay = overlay as? MKCircle else {return MKOverlayRenderer()}


        let renderer = MKCircleRenderer(overlay: circularOverlay)
        renderer.strokeColor = .red
        renderer.fillColor = .yellow
        renderer.alpha = 0.3
        renderer.lineWidth = 2

        return renderer
    }

the warnings I got on the console...

2018-10-25 15:09:04.919237+0200 SeeFire[37911:13344200] This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes. 2018-10-25 15:09:04.921562+0200 SeeFire[37911:13344200] This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.

if I comment the lines where I add the overlay no warnings appear and everything goes just fine, what am I doing wrong?

what's the difference between MKCircleRenderer and MKCircleView how do I know which one should I use?

thank you in advance for the answers.

Lucas
  • 447
  • 5
  • 10
  • You need to modify UI in main thread. Apparently you are doing some in a background thread. Use a `DispatchQueue.main.async { //Put your code where you do UI stuff here }` – Larme Oct 25 '18 at 13:18
  • possible duplicate [https://stackoverflow.com/questions/28302019/getting-a-this-application-is-modifying-the-autolayout-engine-from-a-background?rq=1] – M Abubaker Majeed Oct 25 '18 at 16:11

1 Answers1

0

Try the following code to access from the main thread.

DispatchQueue.main.async {
    mapkitView.addOverlay(geo)
}
Kosuke Ogawa
  • 6,827
  • 3
  • 29
  • 49