How do I extend a NSManagedObject to contain MKAnnotation in Swift?

爱⌒轻易说出口 提交于 2019-12-13 00:40:47

问题


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:


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)
    }
}


来源:https://stackoverflow.com/questions/26995094/how-do-i-extend-a-nsmanagedobject-to-contain-mkannotation-in-swift

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