11. Categories, Extensions, and Security

In Chapter 6, “Classes and Objects,” you learned the basics of defining classes and allocating, initializing, and copying object instances. But there is more to life than simple object creation. This chapter shows you how to add a method to an existing class, how to hide the existence of methods from (at least some) prying eyes, and how to limit access to an object’s instance variables. It also discusses Objective-C security (and the lack thereof).


Categories let you add methods to an existing class without subclassing it and without requiring access to the class’s source code. Using a category to extend the behavior of a class is a much lighter-weight procedure than subclassing.

As an illustration, ...

Get Learning Objective-C 2.0: A Hands-On Guide to Objective-C for Mac and iOS Developers now with O’Reilly online learning.

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