Would it be in any way possible to use an NSString variable as a way of calling a function in XCode?
This is just an example. I have a function called [Settings getBest1] which gets the high score of level one and [Settings getBest2] to get the high score of level two and so on for several levels.
I have an integer value which is the level who's high score I would like to see. What is the best way of coding the app so that I can use this integer to call the right function? Is there no better way than:
switch(levelInt) {
case 1: [Settings getBest1]; break;
case 2: [Settings getBest2]; break;
case 3: [Settings getBest3]; break;
case 4: [Settings getBest4]; break;
...
}
I'd love to be able to do the impossible:
NSString *getBestString = [NSString stringWithFormat:@"getBest%i", levelInt];
[Settings getBestString];
But since that's impossible - is there some other way of accomplishing this idea?