I want to be able to pass an array of variable names to a method which will then run though a loop and display the value of an objects variable I have created in the NSLog.
This is the standard way I have been printing each variable of the object info to NSLog
Code:
NSLog(@"%i. item1: %d", 0, [[[mainDelegate.itemArray objectAtIndex:0] item1] integerValue]);
NSLog(@"%i. item2: %d", 0, [[[mainDelegate.itemArray objectAtIndex:0] item2] integerValue]);
But as there are 15 of them I didn’t want to keep filling up the NSLog with them all. I was thinking that if would be better to just display the ones related to any changes made to them. So I started to make a method that I could pass an array with the names of each variable as a string.
Code to call the method
Code:
NSArray *array = [[NSArray alloc] initWithObjects:@"item1", @"item2", nil];
[self logVariables:array];
Code of the method
Code:
- (void) logVariables:(NSArray *)anArray {
XAppDelegate *mainDelegate = (XAppDelegate *)[[UIApplication sharedApplication] delegate];
for(int i = 0; i < [anArray count]; i++) {
NSString *variableName = [anArray objectAtIndex:i];
NSLog(@"%i. %@: %d", 0, saveVariable, [[[mainDelegate.itemArray objectAtIndex:0] variableName] integerValue]); //error here on variableName
}
}
Whatever I do I can’t get it to accept the string variableName in the NSLog as the variables name.
Any ideas would be greatly appreciated.
mayhem_nz