modifying constants in objective c during run time

Posted by moshikafya on Stack Overflow See other posts from Stack Overflow or by moshikafya
Published on 2012-10-25T04:55:15Z Indexed on 2012/10/25 5:00 UTC
Read the original article Hit count: 145

Filed under:
|
|
|
|

I am trying to solve the following problem. I have the following constants in my header file:

#define PREFS_MY_CONSTANT_1 @"bla1"
#define PREFS_MY_CONSTANT_2 @"bla2"
#define PREFS_MY_CONSTANT_3 @"bla3"
...

In one of my functions, I'd like to print to the UIbutton one of those strings based on user input, so say the user inputs '1', i would show bla1. Instead of creating a huge switch (i have 100 of those), I am looking for a way to combine the constant with the variable holding the user input, so something like that ideally:

NSInteger input;
[button setTitle:PREFS_MY_CONSTANT_{$input} forState: UIControlStateNormal];

Is something like that possible? what would be the best way to solve this?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c