Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL

Chapter 8. Extending Existing Class Capa... > Extending Classes using Anonymous Ca... - Pg. 216

216 Exploring Deeper Features NSObject is a "special class" in that it provides certain functionality to the runtime that other classes do not. The end result of this is that the NSObject class, speaking about the class object itself and not the class definition, is capable of calling object methods. It is the only class in Objective-C that is able to do this. In order to do this, NSObject does some unusual voodoo with the self object. Therefore, self, when used within the context of a category defined on NSObject, they refer to the class or the object. Because of these hazards, generally speaking, you should only declare categories on NSObject in the form of interfaces alone and did not provide implementations. The category implementations should probably be limited to subclasses. Although the capability exists to provide implementations for NSObject categories, for the most part, expect that categories on NSObject will only be used for the purposes of declaring informal protocols. Extending Classes using Anonymous Categories Although Objective-C does not have a mechanism for declaring private methods baked into the class declaration syntax, there is a way of defining a private API, which you exposed only to priv- ileged users of your class and not to others using categories.