Using Super in an Objective C Category?

Categories extend the original class, but they don’t subclass it, therefore a call to super doesn’t find the method.

What you want is called Method Swizzling. But be aware that your code could break something. There’s an article on Theocacao written by Scot Stevenson about Method Swizzling in the old Objective-C runtime, Cocoa with Love by Matt Gallagher has an article about Method Swizzling in the new Objective-C 2.0 runtime and a simple replacement for it.

Alternatively, you could subclass the class and then either use the subclass or use + (void)poseAsClass:(Class)aClass to replace the superclass. Apple writes:

A method defined by a posing class
can, through a message to super,
incorporate the superclass method it
overrides.

Be aware that Apple has deprecated poseAsClass: in Mac OS X 10.5.

Leave a Comment