Search code examples
objective-cobjective-c-category

Objective-C categories with the same name


I have a set of data classes that I'd like to extend with my own methods by creating categories unique to each class.

When declaring a category, does each category need to have a unique name, or can I reused the same name.

Example. Say I have a List class and ListItem class and I want categories on both. What I'm doing now is declaring as follows:

In List+Additions.h

@interface List (Additions) ...

In ListItem+Addtions.h

@interface ListItem (Additions) ...

Is that ok? I can't tell if its consistently working. What is considered the category name? Is it "Additions", or the combination, "ListItem+Additions".


Solution

  • The category names are List (Additions) and ListItem (Additions). So, the two categories are separate and independent.

    Something like "ListItem+Additions" is a common convention for the file names which define the categories, but neither the compiler nor the runtime pay any attention to that.