When I add an MKCircle to the mapKit's overlay I got a lot of warnings in the compiler

112 Views Asked by At

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.

1

There are 1 best solutions below

0
Kosuke Ogawa On

Try the following code to access from the main thread.

DispatchQueue.main.async {
    mapkitView.addOverlay(geo)
}