Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MKAnnotationView layer is not of expected type: MKLayer

Tags:

ios

swift

mapkit

So my code works fine but my logger is riddled with this message. Is there a way to get rid of it or suppress it?

PostAnnotation.swift

class PostAnnotation: MKPointAnnotation {

    //MARK: properties
    let post: Post

    //MARK: initialization
    init(post: Post) {
        self.post = post
        super.init()
        self.coordinate = CLLocationCoordinate2D(latitude: post.latitude, longitude: post.longitude)
        self.title = post.title
        self.subtitle = post.timeString()
    }

}

Adding the annotation

let annotation = PostAnnotation(post: post)
self.map.addAnnotation(annotation)

func mapView

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

    if annotation is MKUserLocation {
        return nil
    }

    var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "pin") as? MKPinAnnotationView
    if annotationView == nil {
        annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "pin")
    } else {
        annotationView?.annotation = annotation
    }

    if let annotation = annotation as? PostAnnotation {
        annotationView?.pinTintColor = UIColor.blue
        annotationView?.canShowCallout = true
        annotationView?.rightCalloutAccessoryView = UIButton(type: .infoLight)
        annotationView?.animatesDrop = true
    }

    return annotationView
}

Removing this function removes the message

like image 736
rmaes4 Avatar asked Sep 13 '17 19:09

rmaes4


1 Answers

This is a bug in iOS 11, since MKLayer is not a public class.

I'd simply ignore the message, but if it's bothering you: To silence this warning, you can set OS_ACTIVITY_MODE=disable in the scheme's environment page. Beware though, you will silence other OS warnings as well.

Scheme Editor

like image 76
DrMickeyLauer Avatar answered Nov 05 '22 20:11

DrMickeyLauer