O'Reilly logo

Objective-C Programmer's Reference by Carlos Oliveira

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

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 ...

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