问题
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