I have an objective C method which passes in a string and an integer as its arguments. Inside of this method, I want to use a selector - the name of which is based upon the integer value I am passing in. For example, if the integer argument is 5, I want the selector to be named "buildXArrayIndex5" or if the integer argument is 3, I want the selector to be named "buildXarrayIndex3." I am really at a loss for how to do this or if it is possible/reasonable. I am new to objective C, so I wrote out what I want to happen, but it is not working/valid code. But here it is:
- (void) startBuildingXArray:(int)senderID:(NSString *)moveTrackerObject {
NSString *methodNamePrefix = @"buildXArrayIndex";
NSString *realMethodName = [[NSString alloc]initWithFormat:@"%@%d",methodNamePrefix,
senderID];
SEL realSelector = NSSelectorFromString(realMethodName);
[self realSelector: moveTrackerObject];
}
In the interface, I declared SEL realSelector; but I am getting an error without running this that says"no visible @interface declares the selector realSelector." But I'm sure that this is not the only problem with this code. Can anyone tell me how to create the proper code for this or highlight a better approach?