0

I would like to know if it is possible to make the name of a variable dynamic:

Instead of this code:

 [images1 addObject:nameBild];
 [images2 addObject:nameBild];
 [images3 addObject:nameBild];
 [images4 addObject:nameBild];

 images1.alpha = 0.5; 
 images2.alpha = 0.5;
 images3.alpha = 0.5;
 images4.alpha = 0.5;

I would like something like this:

for (int i=1; i<5; i++) {
     [images(i) addObject:nameBild];
     images(i).alpha = 0.5;
}

Or like this way:

for (int i=1; i<5; i++) { 
    NSMutableString *string1; 
    NSMutableString *string2; 

    string1 = @”images"; 
    string2 = string1; 

    [string2 appendString: i]; 
    [string2 addObject:nameBild];

    string2.alpha = 0.5;
} 

Can anybody support me in this way? I would be appreciate for an answer. Thanks in advance.

Greetings

Arda Keskiner
  • 772
  • 7
  • 23
  • I don't know nothing about xCode but wouldn't it be easier to make an array for those objects ? – Pierre C. Mar 10 '16 at 12:39
  • Thanks for your answer. I have no clue. I hope it would be solved in this way I tried above. –  Mar 10 '16 at 12:41
  • Just found this [question](http://stackoverflow.com/questions/11073433/incrementing-variable-names-in-xcode). Maybe this can help. – Pierre C. Mar 10 '16 at 12:44
  • Thanks Pierre, I will check it out. –  Mar 10 '16 at 12:47

0 Answers0