Reputation: 19969
not an objective-c programmer but am not sure why I can't access this value:
NSMutableArray *colorsArray=[[NSMutableArray alloc] init];
[colorsArray addObject:[UIColor whiteColor]];
[colorsArray addObject:[UIColor blueColor]];
[view setBackgroundColor:[UIColor [colorsArray objectAtIndex:0]]];
I get an expected identifier
but syntax looks ok to me. Any idea what I'm doing wrong?
thx in advance
Upvotes: 0
Views: 49
Reputation: 164331
The last line should be:
[view setBackgroundColor:[colorsArray objectAtIndex:0]];
You put color instances into the array, so you should just use that to get them out.
I think the confusion comes from the calling of UIColor class methods whiteColor
and ´blueColor` in the lines before. In Objective-C, a message is sent by identifying the receiver class or instance and then specifying the selector part in brackets.
Upvotes: 2