In Swift 3 I'm trying to create a subclass of MapKit's MKPolyline called MKTrack (which I'm planning to give some extra members), but I've problems writing a suitable initializer.
MKPolyline, the superclass, has one designated initializer called init(), which is ultimately inherited from NSObject, and doesn't do a lot. There are two, more useful convenience initializers, which initialize the the polyline with points or coordinates. I would like to base my subclass initializer on one of these. However, the compiler won't let me, since apparentlhy I have to use a designated initializer.
What the compiler does accept and what seems to work is calling two initializers:
class MKTrack: MKPolyline {
.....
convenience init(trackURL: URL) {
self.init()
let parser = Parser()
parser.parseFile(url: trackURL)
self.init(coordinates: &parser.locations, count: parser.locations.count)
}
.....
}
This is a bit weird, in my opinion, calling two initializers, so I'm not convinced that this is the correct approach.
But the compiler doesn't seem to accept anything else, if not calling self.init() and reinventing the already existing code in the convenience initializers of MKPolyline.
Can any one shed some light on this? What am I doing wrong?
Thanks