Chapter     4

Categories and Protocols

A category can be used in Objective-C to add methods to classes, even when you don’t have complete access to the original source file for the class.

For example, using categories it is possible to add new methods to common classes in the system, such as NSString, NSNumber, or even NSObject. Doing this will make the added methods available to any user of the original class, as long as the category is loaded into the application.

If you need to add a complex responsibility to a new class in the context of a new library, or if you’re just trying to add a single convenience method, categories may save the day, and are another reason why programming in Objective-C is so productive.

The design of adaptable interfaces ...

Get Objective-C Programmer's Reference now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.