Overriding original class' methods


#1

Categories are nice. So basically it’s like subclassing, but all the enhancements go onto the original class, not a new class with a new name.

Question… is it possible to override the original class’ methods?

For example, could NSString+VowelCounting redefine NSString’s init method so that it isn’t an empty string by default? If that is possible, would you need to call the original class’s init method from the new init method (like you would call [super init] if it were a subclass)?

I half expect the answer to this question to be “no - that’s what subclassing is for”, but it would be good to know.


#2

It is, actually, possible to completely replace a method of any class using categories. It is not recommended that you replace any of Apple’s methods with your implementation, but you certainly can.


#3

C makes it easy to shoot yourself in the foot. Objective-C makes it harder, but when you do, you blow away your whole leg.