samir
samir

Reputation: 4551

subclassing classes in Cocoa

My question is : Why Apple prohibit some classes to be subclassed, for example MKMapView ?

What is the reason to do this please ?

thanks for your answers

Upvotes: 2

Views: 50

Answers (1)

Stephen Darlington
Stephen Darlington

Reputation: 52565

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.

Upvotes: 1

Related Questions