Maybe I'm trying to abuse the preprocessor. I want to see if it is possible that I mean.
My @properties class has all the same bodies. I want to generate these bodies using a preprocessor macro. For instance:.
- (float) accelerometerSensitivity { return [dict floatForSelector:_cmd or:1]; } - (void) setAccelerometerSensitivity:(float) n { [dict setFloat:n forSelector:_cmd]; [dict writeToFile:[self globalDataFilename] atomically:YES]; } - (float) returnSpringTension { return [dict floatForSelector:_cmd or:0]; } - (void) setReturnSpringTension:(float) n { [dict setFloat:n forSelector:_cmd]; [dict writeToFile:[self globalDataFilename] atomically:YES]; }
The idea is that instead of using string literals (or string constants) as keys in a dictionary, I get a string from the name of the selector. Thus, I am sure that the spelling of the key matches the name of the property and, in fact, has the advantage of checking the dictionary time with keys.
What I want to do is say something like SELECTOR_PROPERY(accelerometerSensitivity) and propagate it to getter and setter. The main difficulty that I experience when implementing this as a preprocessor macro is to generate the installer name from the property name. I need to smooth out the first letter of the property name, and I do not know how to do this in the preprocessor.
source share