MKAnnotationView layer is not of expected type: MKLayer

邮差的信 提交于 2019-12-04 09:08:22

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/46205686/mkannotationview-layer-is-not-of-expected-type-mklayer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!