29 JulHelpful primitive #DEFINEs I really like

#define cgp(x,y) CGPointMake(x,y)#define cgpz CGPointMake(0,0)
#define cgf(x,y,w,h) CGRectMake(x,y,w,h)

#define NUM(i) [NSNumber numberWithInt:i]#define NUMF(f) [NSNumber numberWithFloat:
f]// etc if you need, I don’t// this one is MUST HAVE EVER#define IMG(name)
[UIImage imageNamed:name]#define NSTR(patern, value) [NSString stringWithFormat:patern,
value]#define NSTR2(patern, value1, value2) [NSString stringWithFormat:
patern, value1, value2]#define INT2STR(i) [NSString stringWithFormat:@"%d",
i]#define FLT2STR(i) [NSString stringWithFormat:@"%0.2f", f]// etc if you needThe most important reason not to use #DEFINE is code readability, imho. Everyone can define own abbriveations and then get dead code. I mean not an Unreachable code, but code that nobody else can support effectively, even an author after months left. It’s easy to get addicted and generate shorteners for every partially doubled line.

That’s why I propose only helpful #defines I use almost in every project. They look very simple and even obvious. I place them in the precomiled *.pch file to be availabe in all sources.

This helps with coordinates:

This helps with string creation and constants:

Other small objects:

There are 10 more for subviews creation, but it’s more like an approach than promitive shortneners. I’ll describe that later with samples.

I’ve googled a little and there are some nice links on that:

I suppose it helps begginers only. Others can write their experience in comments.
No comments

Place your comment

Please fill your data and comment below.
Name
Email
Website
Your comment


1 * one =