I’ve created a Constants.h file with a list of:
#define kw00 @"foo"
#define kw01 @"bar"
...
I also use #import Constants.h in the .h. Using newQuote method, I’m trying to randomly select one of the kw strings, but am having difficulty discovering how to call a reference to a constant that is defined within the string kwString.
-(IBAction)newQuote
{
int rNumber = arc4random() % kwTotal;
(rNumber <9)
{
NSString *kwString = [@"kw0" stringByAppendingString:[NSString stringWithFormat:@"%d", rNumber]];
}
}
Thoughts and suggestions would be most appreciated.
It simply isn’t possible to access things this way. Those “constants” don’t even exist at runtime, or when the compiler sees your code — they’re translated by the preprocessor into literal strings.
You should instead create an array, and then you can just get the element at a given index.
(In general, any time you’re naming things with sequential numbers on the end, the answer to any problems you might have is “Use an array.”)