【发布时间】:2017-12-08 22:18:40
【问题描述】:
我有一个带有注释作为属性的类
class UserClass {
var id : String?
var annot : MKPointAnnotation?
}
然后我创建了这个类的几个实例,例如:
var user1 = UserClass()
然后在地图上定义、创建和添加每个用户的注释。
稍后在代码中,用户点击注释,我需要对相应用户实例的引用。如何获得?
@objc(mapView:didSelectAnnotationView:) func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
if let annot = view.annotation as? MKPointAnnotation {
let user = // Need the user instance here to acces user id etc
}
}
【问题讨论】:
-
你怎么知道点击注释对应的是某个用户?
-
因为我正在为每个用户创建一个注释
标签: swift class properties