So the other day I was sick of typing out repetetive addTarget:action:forControlEvents:s, and macros are only entertaining for so long, so I did this:
@implementation UIControl (xx)
-(void)addTarget:(id)target action:(SEL)action
{
[self addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
}
@end
*and simply added it at the top of the .m file in question.
Works great of course, but notice the "xx".*
What's the best thing to NAME a "quick" Category like this?
Annoyingly, it appears you can not leave the xx blank - it would then become an "Extension" (which, incidentally, I don't understand at all).
I was thinking maybe:
a single underscore
the name of the class again identically
"quick"
perhaps the name of the class in this file (as in "quick extra routines for UIControl in CherryBomb") - so it would be UIControl(CherryBomb), ie, remind you that these extra routines are handy for CherryBomb
"x"
your or your company's initials (use the same "quick" Category name everywhere)
"ThisTextNeverUsedAnywhere"
By the way, I've been assuming that Categories only happen in the files that see them (CherryBomb.m in the example) - they do not from then on apply app-wide. ie they only apply where you include the header file (UIControl+NattyStuff) or in the "quick" case only in the file to which one adds the text.
(By the way ... it appears you do not actually need to include an interface for such a Category, i.e. you can omit...
//you can actually get away without these lines...
//#import <UIKit/UIControl.h>
//@interface UIControl (x)
//-(void)addTarget:(id)target action:(SEL)action;
//@end
... that part and it works fine.)
For people who love Categories, and who doesn't, what's the answer to this troubling question?
What should you name a "quick" Category where the name is never going to be referenced again and is irrelevant? Is "_" a solution?