CHAPTER 19

image

Categories

Categories Defined

Categories are used to extend classes without using inheritance. When you use a category, you can add properties and methods to a class without declaring a super class.

To define a category, you need to add an interface and implementation. You can do this by adding new header and code files or you can add the categories right in the code file where you are working.

Category Example

As an example, let’s say that you want to take the Project class that you defined in Chapter 16 and add a constructor method that would initialize a new Project object and assign a name at the same time. You could add code like ...

Get Objective-C Quick Syntax Reference 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.