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

Cant pass code challenge - animation IOS NSArray objects

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

I can't get past it! help! this is what i have:

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

14 Answers

It should be:

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

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

You have the right idea about the pieces you need, but your syntax is just a little off. Study the line of code Amit writes starting at the 5:50 mark of the Image Based Animation video and you should be able to figure out how the initWithObjects: method call should work.

Hi I have the same problem. I just cant get past that challenge. PLEASE help me! I watched the vid you said to see and cannot find out anything more than I already know.

Also stuck with this! Please help. This is what I have so far:

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

Also tried:

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

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

@Andy - check out how you're declaring your array. @Blake has that part right in the original code posted.

@Raphael, can you paste your code in here? We don't like to post the exact answers but we're happy to help you step by step. :smiley:

I thought it was something like

self.imageView.robotImages = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"Robot1"],
[UIImage imageNamed:@"Robot2"],
[UIImage imageNamed:@"Robot3"],
[UIImage imageNamed:@"Robot4"], nil];
Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

@Noah, let's look at the left side of your equals sign, i.e. what you're assigning into:

  • self: Current object (View controller)
  • self.imageView: a UIImageView property of the current object
  • self.imageView.robotImages: a 'robotImages' property of the Image view

So that syntax means that your robotImages 'thing' is a property of the imageView property, which isn't correct. The challenge is looking for a new array (NSArray) variable named 'robotImages'.

Hope I didn't muddy the waters! Good luck!

Hey guys, I'm also struggling with that code challenge. I am aware that I don't get the idea with properties and instances...

That's what I got so far: I think, I create in the first line an array called robotImages, allocate it and add the image objects. what exactly is the 2nd step i need to do? anybody has a hint?

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

Thanks alfonso, this is unfortunately still not working. <p> <code> NSArray *robotImages = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"Robot1"]; [UIImage imageNamed:@"Robot2"]; [UIImage imageNamed:@"Robot3"]; [UIImage imageNamed:@"Robot4"], nil];</code>

I'm sorry I had a typo. The correct code is as follows:

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

This is for sure correct because I just tested it.

Hello I am stuck here as well.. I am a complete newbie to programming anything I am getting allot of it but am completely lost on this project Ive watched the video about 20 times now and read over his code I've tried everything including putting @synthesize robotImages; at the tope of the challenge... am I thinking about this all wrong or am I getting my code mixed up in my head Im sorry @Ben but your explination to @ Noah has made the waters go from murky to complete mud..

Please Help

This is what I have now

@synthesize robotImages;

UIImage *image = [UIImage imageNamed:@"robot.png"];

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

/* Write your code below this line */

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

I found my mistake [UIImage: imageNamed: @"Robot3"],

type O where UIImage: I removed the : and the code worked.. its just too bad the artificial compilier used by the online program keeps saying that I set didnt set NSAarray *robotImages properly when it should of been telling me I had a syntax error

thanks Mike

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Hey @Michael,

Glad you figured it out! Hopefully we can continue to improve the code challenge engine to give you more and more information about the error like Xcode would.

This worked for me, NSArray *robotImages = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"Robot1.png"], [UIImage imageNamed:@"Robot2.png"],[UIImage imageNamed:@"Robot3.png"],[UIImage imageNamed:@"Robot4.png"],nil];

Thanks Kapil