I’m running into problems with a selector. I’m trying to dynamically name an array, winnerArray1, winnerArray2, winnerArray3, etc.
The variable someVariable is in a loop that increases so that will get incremented.
I get unrecognized selector sent to instance
int someVariable = 1;
NSArray *winnerArray;
NSString *tempLoopString;
while(someVariable < 4){
tempLoopString = [NSString stringWithFormat:@"winnerArray%d", someVariable];
SEL selector = NSSelectorFromString(tempLoopString);
winnerArray = [self performSelector:selector];
if ([winnerArray do_stuff]) {
do stuff here
}
someVariable++
}
You can’t refer to a variable by name like that.
You should look into using key value coding. With that, you can interrogate a property of some object using the method valueForKey: