I'm trying to set up a class that inherits from MKPolygon as below, but the compiler rejects my call to super.init()
with the following error message:
Must call a designated initializer of the superclass 'MKPolygon'
What is the designated initializer for MKPolygon
?
Following the advice of this answer and this one, I've scoured the class documentation. There are four initializers available but all of them are declared as Convenience Initializers.
- init(points: UnsafePointer, count: Int)
- init(points: UnsafePointer, count: Int, interiorPolygons: [MKPolygon]?)
- init(coordinates: UnsafePointer, count: Int)
- init(coordinates: UnsafePointer, count: Int, interiorPolygons: [MKPolygon]?)
I'm fairly new to Swift so I'm sure there's something simple I'm missing.
My subclass implementation is below, in case that helps.
import MapKit
import UIKit
class AudioGuideRegionAnnotation: MKPolygon {
// MARK: - Properties
let color: UIColor
let image: UIImage?
// MARK: - Initializers
init(region: AudioGuideRegion) {
var locations = region.locations
super.init(coordinates: &locations, count: locations.count) // <-- rejected with "Must call a designated initializer of the superclass 'MKPolygon'"
self.title = region.title
self.subtitle = "\(Int(round(Double(region.duration / 60)))) minutes"
self.color = .black
self.image = region.images.first?.image
super.init()
}
}