I currently have a loop which iterates through an NSArray of NSString objects. I would like an NSString variable to be created on each iteration of the loop, using the currently evaluated NSString object’s string value (from the NSArray) as the name of the variable. This is probably best explained through example:
for (i = 0; i < [arrayOfStrings count]; i++) {
// NSString *<name of variable is [arrayOfStrings objectAtIndex:i]> = [[NSString alloc] init];
}
Is there anyway to accomplish this task? I am using iPhone SDK 3.1. Thanks.
Not exactly but you could use an NSMutableDictionary to add key/value pairs at runtime where the key is the name from the array of strings. See http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/Reference/Reference.html.