Hello Anthony!
Yes you can. (c) :)
For the solution I suggest to work you will need to be able to access (set/get) your variables via methods (easily done using properties or writing your own setters and getters).
Here's an example:
- (void)performAction:(NSMutableString *)text {
[(UIImageView *)[self performSelector:NSSelectorFromString([text stringByAppendingString:@"Pic1"])] setHidden:YES];
[(UIImageView *)[self performSelector:NSSelectorFromString([text stringByAppendingString:@"Pic2"])] setHidden:NO];
}
As for properties I actually thought about simply giving you a sample code to get start using this great feature of Objective-C ASAP, which I will do. Though I'm not sure about going deep into this topic because it may require too much of Internet paper, so that's why after the sample code I'll also add a few links for further reading.
@interface AClass : NSObject {
// Here's where you declare variables
NSObject *objectForInternalUseWeWantToBeRetained;
id linkToObjectUsuallyNotRetained;
int nonObjectVariable;
BOOL aVariableWithARenamedGetter;
}
// And here's where their properties are declared
@property (nonatomic, retain) NSObject *objectForInternalUseWeWantToBeRetained;
@property (nonatomic) id linkToObjectUsuallyNotRetained;
@property (nonatomic, assign) int nonObjectVariable;
@property (nonatomic, assign, getter=renamedVariableGetter) BOOL aVariableWithARenamedGetter;
@end
@implementation AClass
// Here we command the machine to generate getters/setters for these properties automagically
@synthesize objectForInternalUseWeWantToBeRetained, linkToObjectUsuallyNotRetained, nonObjectVariable, aVariableWithARenamedGetter;
// But you can implement any of the getters/setters by yourself to add some additional behaviour
- (NSObject *)objectForInternalUseWeWantToBeRetained {
// Some additional non-usual stuff here
// And after that we do the getters job - return the variables value
return objectForInternalUseWeWantToBeRetained;
}
// And of course we don't forget to release all the objects we retained on dealloc
- (void)dealloc {
[objectForInternalUseWeWantToBeRetained release];
[super dealloc];
}
@end
// And here's where their properties are declared
@property (nonatomic, retain) UIImageView *testPic1;
@property (nonatomic, retain) UIImageView *testPic2;
@end
Warning: I ran through the suff very quickly. Here's a nice tutorial at CocoaCast blog - Properties in Objective-C 2.0, which I think might be a good starting point. BTW they provide a lot of learning materials (podcasts, screencasts, etc) so browsing their site further might be useful. And of course the main place to learn all about Objective-C and Cocoa is official documentation, here's where it is about properties.