Chapter 8. Extending Existing Class Capabilities

In This Chapter

  • Extending existing classes with categories

  • Exposing private APIs using anonymous categories

  • Adding variables to classes using associative references

No matter how well designed a class or framework is, inevitably, there will always be circumstances that you will encounter that the framework designer did not anticipate. Some developers go so far as to say that you should not plan for reusability in your code because at the end of the day, it is so difficult to achieve true universal reusability. I disagree with this notion, and I think that Objective-C provides some of the best tools for fostering reusability of any language available today.

In this chapter, I'm going to delve into some of the most powerful of those tools. While not completely unique to Objective-C, they are certainly examples of how the dynamism of Objective-C enables more flexibility and reuse than almost any other compiled language.

The technologies that I explain in this chapter center on the ability to extend the functionality of existing classes.

Working with Third-Party Frameworks and Classes

If you've worked with any kind of programming frameworks at all in the past, you've probably run into a situation in which existing classes that are provided by the standard library of the language give you about 90 percent of the functionality that you're looking for, but not the final 10 percent of the functionality that you really need. For example, you might ...

Get Objective-C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.