subclassing classes in Cocoa
My question is : Why Apple prohibit some classes to be subclassed, for example MKMapView ?
What i开发者_高级运维s the reason to do this please ?
thanks for your answers
The short answer is that although they look like normal classes, they probably aren't. This means that subclassing them without some knowledge of how they're implemented probably won't do what you're expecting.
There are some, like the collection classes, that you can subclass but you need to follow some documented rules. And there are others that they just say "don't." I've seen developers ignore this advice only to find that their app breaks on the next iOS update.
The good news is that the way that these classes are implemented usually means that if you're trying to subclass them you're probably doing it wrong. Cocoa heavily relies on delegates and composition, which means that you tend to subclass system components far less often than you would in other frameworks such as Java and .Net.
精彩评论