Free Trial

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


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

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

8.3. 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 privileged users of your class and not to others using categories.

The tool that you use to do this is called an anonymous category. Essentially, an anonymous category is a category declared on a given class without a name. That is, when you declare the category, rather than placing the name of the category inside parentheses after the category name, the parentheses are there, but they are left empty. When working with anonymous categories, you declare only the interface, but not the implementation as part of the category itself. Typically, you place this category declaration in another header file that can be imported by users of your class that have access to the private API. The implementation is done inside the implementation of the original class. You are simply creating a mechanism for accessing that implementation externally.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial