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

iOS

course "Build a Simple iPhone App" , step 5, "Animate this", Code Challenge # 1 : Image Based Animation

i'm totally blocked on the first question :

Assume you have images named 'Robot1.png','Robot2.png','Robot3.png','Robot4.png', create an array of UIImage objects called 'robotImages'.

Here's my code :

UIImage *image = [UIImage imageNamed:@"robot.png"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; NSArray *robotImages = [NSArray alloc]; robotImages = [ initWithObjects: [UIImage imageNamed:@"Robot1"], [UIImage imageNamed:@"Robot2"], [UIImage imageNamed:@"Robot3"], [UIImage imageNamed:@"Robot4"], nil];

The compiler is saying that "Make sure you create an NSArray named 'robotImages' with instances of UIImage objects."

Any clue about what have i've made incorrectly ?

You are very close...

To create the NSArray you are calling the alloc but adding a ; and missing a open bracket... try something like this: NSArray *robotImages = [[NSArray alloc] initWithObjects:@"Robot1.png", @"Robot2.png", @"Robot3.png", Robot4.png", nil];

1 Answer

i've found the solution. Here's my code :

UIImage *image = [UIImage imageNamed:@"robot.png"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

NSArray *robotImages = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"Robot1"], [UIImage imageNamed:@"Robot2"], [UIImage imageNamed:@"Robot3"], [UIImage imageNamed:@"Robot4"], nil];

everything worked fine !!