Ben Hanzl
Ben Hanzl

Reputation: 45

What is the naming convention or coding standard for categories in objective-c?

I saw an example in The iPhone Developer's Cookbook that extends the UIDevice class using categories.

@interface UIDevice (Reachability)
   // some methods
@end

Typically classes are nouns and methods are verbs. From my point of view categories are similar to subclasses, so I would name the category a noun such as NetworkedUIDevice. How should the name of the category be determined?

Upvotes: 2

Views: 619

Answers (1)

Ole Begemann
Ole Begemann

Reputation: 135548

I don't think a strict naming convention is established. Personally, I would go with something like @interface UIDevice (ReachabilityAdditions).

More importantly, you should add a custom prefix to your category methods to avoid namespace conflicts. And this prefix should probably be included in the category name as well.

Upvotes: 3

Related Questions