Alex K. Alex K. - 9 months ago 240
Swift Question

MKMapSnapshotter takes long time for creating Image

I have a working MKMapSnapshotter in my awakeWithContext and i want to set its image for my imageView.

The problem is, that the MKMapSnapshotter is to slow and the image won't be set. Only one or two seconds later, it creates the snapshot image.

override func awakeWithContext(context: AnyObject?) {

var finalImage = UIImage()
var snapshotterEnd = MKMapSnapshotter()
snapshotterEnd.startWithCompletionHandler(){snapshot, error in

finalImage = snapshot.image

How can i fix this?


You need to make sure that the completion handler itself will set the image.

snapshotterEnd.startWithCompletionHandler() { snapshot, error in

The completion block is documented as running on the main thread so you don't need to use dispatch_async to run it there.