tato tato - 16 days ago 6
iOS Question

Is it possible to inherit from MKPolyline

I'm building a MapKit based app for iPhone.

I have a number of MKPolylines added to the map.

However, instead of having a MKPolyline, I would like to have my own Model class conforming to the MKOverlay protocol added to the map so that I can access the model properties when creating the corresponding view in mapView:viewForOverlay.

The problem is that I can't find the way to inherit from MKPolyline because it doesn't have any init methods that I can call from the subclass' init. You can only create them using the convenience methods.

How can I bring together the model properties and the MKPolyline behaviour?

Answer

You can set an associated object attribute of the class. This allows you to bind an instance variable to an existing class. Make sure you properly clean up after yourself.

Comments