O'Reilly logo

Cocoa Design Patterns by Donald A. Yacktman, Erik M. Buck

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

6. Category

The Category pattern adds methods to existing classes and provides an alternative to subclassing in many situations. The Category pattern is supported directly by the Objective-C language and is used extensively in the implementation of other Cocoa design patterns. The added methods are inherited by all subclasses of the extended class and are indistinguishable at runtime from methods originally compiled into the class.

The Category pattern can also be used to replace the implementations of methods in existing classes, perhaps to fix bugs in framework classes without needing source code for those classes. However, there is no convenient way to call the original method from the code that replaces it. When replacing a method, you must ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required