delay showing UIMapView until map fully loaded in Swift

128 views Asked by At

On my story board, I have set up a timer (which updates every 0.01 seconds) and a UIMapView which displays the user's location when the view controller is loaded. However, when this screen loads, the timer lags for a bit until the map is fully loaded. I assume this is because the loading of the map is a blocking function performed on the main thread.

Is there any way to load the map in the background and display it after it has fully loaded while still keeping the timer running?

1

There are 1 answers

0
Duncan C On BEST ANSWER

Probably not. A map view is a view object and view objects are not thread safe.

Note that Apple's docs on NSTimer say:

A timer is not a real-time mechanism; it fires only when one of the run loop modes to which the timer has been added is running and able to check if the timer’s firing time has passed. Because of the various input sources a typical run loop manages, the effective resolution of the time interval for a timer is limited to on the order of 50-100 milliseconds.

50 ms is .02 seconds. 100 ms is .04. Thus you are not likely to get the accuracy you need.