我不确定如何用swift语言对地图进行注释。我不知道如何创建NSObject类。下面是我尝试过但无法运行的代码:
import Foundation
import MapKit
class MapPin : MKAnnotation
{
var mycoordinate: CLLocationCoordinate2D
var mytitle: String
var mysubtitle: String
func initMapPin (coordinate: CLLocationCoordinate2D!, title: String!, subtitle: String!)
{
mycoordinate = coordinate
mytitle = title
mysubtitle = subtitle
}
}发布于 2014-06-16 04:43:02
Swift中的所有初始化方法必须简单地为"init"
这将为您提供结果:
class MapPin : NSObject, MKAnnotation {
var coordinate: CLLocationCoordinate2D
var title: String?
var subtitle: String?
init(coordinate: CLLocationCoordinate2D, title: String, subtitle: String) {
self.coordinate = coordinate
self.title = title
self.subtitle = subtitle
}
}https://stackoverflow.com/questions/24233873
复制相似问题