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

Help w/ Code Challenge: Image Based Animation

I'm having a bit of trouble on the Code Challenge: Image Based Animation. Here it is:

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

So far I have:

/* Write your code below this line */
self.imageView = [[NSArray alloc] initWithObjects:
                                  [UIImage imageNamed:@"Robot1"],
                                  [UIImage imageNamed:@"Robot2"],
                                  [UIImage imageNamed:@"Robot3"],
                                  [UIImage imageNamed:@"Robot4"],nil ];

I keep getting the error: Bummer! Make sure you create an NSArray named 'robotImages' with instances of UIImage objects.

I can't seem to figure out how to name the Array. Any help?

5 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

You are so close! Let's break apart your code to first see what's giving you the error, and then we can get into how to solve it.

On the left side of the equals sign (assignment operator), you have self.imageView. That's a reference to a variable of type UIImageView. But on the right side, you are creating an array of UIImages, which is a different type of object. It holds UIImages, but the array itself is what's different.

So you need to fix the self.imageView half, but your code on the right side of the equals sign is correct. That code creates an array of UIImage objects, so you need to store it in a variable of the appropriate data type.

In the video, check out the code around the 5:45 mark. Amit is using a property of the self.imageView variable called animationImages. Specifically study the variable and data type inside the autocomplete box around the 5:58 mark.

Lastly, make sure you name the variable exactly as the instructions specify. Hope this helps!

Thanks for the reply Ben!

Hmmm, I studied the video again. I'm still struggling. So my code to the right of the assignment operator is correct right?

Would this be considered naming the variable?:

self.imageView *robotImages =

If so, am I looking for the variable that goes right after

.imageView  

and before

*robotImages ?
Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Close...in the Autocorrect box, the data type on the left is "NSArray". Remember that when you are declaring a variable, you first type the data type and then the name of the variable. You have the name correct with *robotImages, so all you need is the correct data type in front of it.

Ohhhhhhh wow.

NSArray *robotImages =

Right in my face! I got it!

Thanks for the help Ben. Also, thanks for trying to lead me to it rather than just telling me the answer. :)