How to increment a value using a C-Preprocessor?
- by mystify
Example: I try to do this:
static NSInteger stepNum = 1;
#define METHODNAME(i) -(void)step##i
#define STEP METHODNAME(stepNum++)
@implementation Test
STEP {
// do stuff...
[self nextFrame:@selector(step2) afterDelay:1];
}
STEP {
// do stuff...
[self nextFrame:@selector(step3) afterDelay:1];
}
STEP {
// do stuff...
[self nextFrame:@selector(step4) afterDelay:1];
}
// ...
When building, Xcode complains that it can't increment stepNum. This seems logical to me, because at this time the code is not "alive" and this pre-processing substitution stuff happens before actually compiling the source code. Is there another way I could have an variable be incremented on every usage of STEP macro, the easy way?