- All initialization methods in Swift must simply be "init"
- MKAnnotation requires that the object inherit from NSObjectProtocol. To do that, you should have your class inherit from NSObject
- You should declare your properties to match those of the MKAnnotation protocol
- You should not declare your parameters as Implicitly Unwrapped Optionals unless you really have to. Let the compiler check if something is nil instead of throwing runtime errors.
This gives you the result:
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
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…