I’m not sure if I worded the subject correctly. I am looping through an array, within each loop I am trying to instantiate a class, but I want to dynamically create the name. Like so:
int i = 0;
for(NSString* thisdatarow in filedata) {
i++;
NSString* thisad = [NSString stringWithFormat:@"ad%d", i];
NSLog(@"%@", thisad);
AdData* thisad = [AdData new];
}
In the example above I want AdData* thisad… to be named dynamically – “ad1”, “ad2”, “ad3″…and so on. I get a conflicting type error.
This code also generated an error:
int i = 0;
for(NSString* thisdatarow in filedata) {
i++;
AdData* [NSString stringWithFormat:@"ad%d", i] = [AdData new];
}
Is there a way to do this?
You can’t do that in Objective-C.
Use a NSString to AdData map–it’ll do basically the same thing!
**edit: To clarify, use an:
with keys that are NSString* objects containing the ad names, and values that are the AdData* objects.
i.e.
to set the values, and
to get the values. (ignore the obvious memory leaks there with the strings…)