如何扩展NSManagedObject以在Swift中包含MKAnnotation? [英] How do I extend a NSManagedObject to contain MKAnnotation in Swift?

查看:130
本文介绍了如何扩展NSManagedObject以在Swift中包含MKAnnotation?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Photo类

class Photo: NSManagedObject {
}

我想扩展它以提供MKAnnotation

I want to extend it to provide MKAnnotation

我试过这样做

extension Photo: MKAnnotation  {

    var coordinate: CLLocationCoordinate2D

然而,编译器抱怨扩展名不能存储属性。

However the compiler complains that extensions cannot have stored properties.

有没有更好的完成这个的方法?

Is there a better way of accomplishing this?

谢谢。

推荐答案

你不能拥有存储的属性,但你可以有计算属性!

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

即:

var coordinate : CLLocationCoordinate2D {
    get {
        return CLLocationCoordinate2D(latitude: 10.0, longitude: 10.0)
    }
}

这篇关于如何扩展NSManagedObject以在Swift中包含MKAnnotation?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆