views:

30

answers:

1

sorry for the simple question but how do you make a CAlayers using a for loop? I have this now but what is the proper way of doing this?

for (int n = 1; n <= 6; n++) {
    NSString *theCloud = [NSString stringWithFormat:@"cloudImage%d",n];
    NSString *theCloudLayer = [NSString stringWithFormat:@"cloudLayer%d",n];

    CALayer *theCloudLayer = theCloud.layer;
}

any help is appreciated.

A: 

Use an NSArray or NSMutableArray, not a bunch of variables with numbers at the end of their names (also known as a Poor Man's Array).

So that would be something like:

NSArray *cloudImages; // Use this to store your objects currently in the cloudLayerN variables
NSMutableArray *cloudLayers = [NSMutableArray array];
for (id cloud in cloudImages) {
    [cloudLayers addObject:[cloud layer]];
}
Chuck
thank you, this is exactly what iv been trying to find
Ryan Erb