ios - 无法在 Swift 中遵循 MKAnnotation 协议(protocol)

标签 ios swift mapkit mkannotation

当我尝试遵循 MKAnnotation 协议(protocol)时,它抛出错误我的类不符合协议(protocol) MKAnnotation。我正在使用以下代码

import MapKit
import Foundation

class MyAnnotation: NSObject, MKAnnotation
{

}

同样的事情也可以用 Objective-C 实现。

最佳答案

您需要在调用中实现以下必需属性:

class MyAnnotation: NSObject, MKAnnotation {
    var myCoordinate: CLLocationCoordinate2D

    init(myCoordinate: CLLocationCoordinate2D) {
        self.myCoordinate = myCoordinate
    }

    var coordinate: CLLocationCoordinate2D { 
        return myCoordinate
    }
}

关于ios - 无法在 Swift 中遵循 MKAnnotation 协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29300565/

相关文章:

ios - UITableViewCell 中有效的长文本绘制

ios - Apple Healthkit 和 Watch 模拟器

Swift 导航栏背景色白色不起作用

ios - 在 iOS MapKit 中通过经纬度坐标判断国家

xcode - 是否可以使用mapkit创建自定义 map ?

iphone - 用 quartz 绘制航向角 View

ios - 返回按钮调用方法

iPad 上的 jQuery animate(向左滑动)...如何提高性能?

ios - 如何在启动屏幕 Swift 3 上创建渐变层

Swift 调试器间歇性无法打印局部变量的描述