How do I extend a NSManagedObject to contain MKAnn

2019-08-10 17:09发布

I have a Photo class

class Photo: NSManagedObject {
}

I want to extend it to provide MKAnnotation

I tried doing it so by

extension Photo: MKAnnotation  {

    var coordinate: CLLocationCoordinate2D

However the compiler complains that extensions cannot have stored properties.

Is there a better way of accomplishing this?

Thanks.

1条回答
手持菜刀,她持情操
2楼-- · 2019-08-10 17:38

You cannot have stored properties, but you can have calculated properties!

I.e:

var coordinate : CLLocationCoordinate2D {
    get {
        return CLLocationCoordinate2D(latitude: 10.0, longitude: 10.0)
    }
}
查看更多
登录 后发表回答