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

Chapter 22. Categories

Although the engineers at Apple are very wise, one day you will think, “Golly, if only they had put that method on that class, my life would be so much easier.” When this happens, you will want to create a category, a collection of methods that you would like added to an existing class. The category concept is very useful, and I find it surprising that so few object-oriented languages include this powerful idea.

Creating categories is easier than talking about them. In the previous chapter, you added pasting capabilities to your BigLetterView. Note, however, that if the string on the pasteboard has more than one letter, the paste attempt will fail, because BigLetterView is capable of displaying only one letter at a time. Let’s extend the example to take only the first letter of the string instead of failing.


  

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