Rather than having to type repetitions, is there a way to use a for loop to execute the below code?
bar1 = [[UIView alloc] init];
bar1.backgroundColor = [UIColor blueColor];
[self addSubview:bar1];
bar2 = [[UIView alloc] init];
bar2.backgroundColor = [UIColor blueColor];
[self addSubview:bar2];
bar3 = [[UIView alloc] init];
bar3.backgroundColor = [UIColor blueColor];
[self addSubview:bar3];
bar4 = [[UIView alloc] init];
bar4.backgroundColor = [UIColor blueColor];
[self addSubview:bar4];
bar5 = [[UIView alloc] init];
bar5.backgroundColor = [UIColor blueColor];
[self addSubview:bar5];
You could use a C array:
or you can use an
NSArray:or if you want to hold on to those individual properties, you could go ‘stringly-typed’ and use KVC:
or
but there are a few other options. Hope that’s enough to get you started!