A category extends the functionality of Apple's in-built classes without subclassing. We do this by first of all creating a header and implementation file for the category by using the Objective-C category template. Next we add our method to the category's .m file:
@implementation UIColor (seeThroughBlue)
return [UIColor colorWithRed:0 green:0 blue:1 alpha:0.5];
(Note: I'm extending UIColor and have called the category seeThroughBlue - Xcode has added UIColor+ to the filenames for convenience)
Next we need to add this method to the .h file:
@interface UIColor (seeThroughBlue)
You'll notice that the name of the category (seeThroughBlue) isn't the same as the filename, because it doesn't need to be.
Finally, to make it globally available we add it to the appName-Prefix.pch file (in your supporting files folder):
#warning "This project uses features only available in iOS SDK 5.0 and later."
#import <Foundation/ Foundation.h>
Now if we want to call the new method from our category we can do so without importing anything extra. For example inside one of our view controller methods we might write:
And that's all, no need to import the category into the view controller .h and .m files.
Full blogpost: http://sketchytech.blogspot.co.uk/2012/09/extending-classes-with-categories-in.html