Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Jason LaGreca
1,150 PointsTo create an NSArray of UIColor objects...
Hi all,
I finished the Crystal Ball app a while back, but before moving on to the Blog Reader, I decided that I wanted to try knocking out the 'extra credit' challenges. I don't know why, as it seems simple, but I can't figure it out!
Im guessing the logical process is: 1) create color objects 2) create array 3)add objects to array 4) add randomization to array 5) add array to the 'buttonPressed' (or in my case, the 'makePrediction') method
Does this sound right to you guys? I'm sure that I could just google this, but I like trying to figure it out on my own....until now!
Thanks, Jason
4 Answers
Amit Bijlani
Treehouse Guest TeacherYou declare a new color object using a convenience constructor. Let's say you wanted to declare a red color then you would declare it like this:
UIColor *redColor = [UIColor redColor];
See the UIColor documentation for the other available colors.
So in your case you would do the following:
self.colorArray = [[NSArray alloc] initWithObjects:[UIColor redColor],[UIColor blueColor],[UIColor greenColor],nil];
Amit Bijlani
Treehouse Guest TeacherSounds about right except that you could combine steps 1, 2 & 3 in one statement.
Jason LaGreca
1,150 PointsThanks Amit.
Jacob Thirty
Full Stack JavaScript Techdegree Student 14,937 PointsI inserted "@property (strong, nonatomic) NSArray *colorArray;" in VC.h and "@synthesize colorArray;" in VC.m but now i'm stuck at how to implement UIColor instead of a literal string. Help?
self.colorArray = [[NSArray alloc] initWithObjects:
//implementation here
nil];