I would like the MKMapItem
returned from MKLocalSearch
to contain an "altitude" property. In order to achieve this, I've decided to create a subclass for MKMapItem
.
class MapItemGeoSpatial: MKMapItem {
var altitude: Measurement<UnitLength>
public init(placemark: MKPlacemark, altitude: Measurement<UnitLength>) {
self.altitude = altitude
super.init(placemark: placemark)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
While the above implementation compiles, it results in a fatal error when attempting to initialise MapItemGeoSpatial
.
Fatal error: Use of unimplemented initializer 'init()' for class 'MapItemGeoSpatial'
The above error occurs during the super.init(placemark: placemark)
call.
I can create an override init()
for the above class, but this will require me to initialise the altitude
property, which is not specified for this initialiser. Initialising altitude
by specifying a dummy variable (eg. 0
) overcomes this issue, but appears to be a poor workaround. Making altitude
optional is another workaround, but this is not a direction I wish to take.
I'm aware that MKMapItem
inherits from NSObject
and I'm curious if this relation has an influence on the above observation. I would like to i) understand the root cause behind this issue and ii) determine if subclassing MKMapItem
is a viable solution to the problem mentioned at the start of this post.