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

Cannot Pass Introduction to Arrays Code Challenge

NSArray *myArray = [[NSArray alloc] initWithObjects:@"Apple",@"Orange",@"Bannana",@"Plum", nil]; 
self.myLabel.text = [myArray objectAtIndex:0];

That's my code. The first line was completed, and marked as correct. However, when I do the second step and add the second line, it is marked as wrong. Any ideas to why that is?

4 Answers

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

@Paul in the second line you are assigning the value returned from the myArray to a label but in this case, it is non-existent. It exists in the context of the project but the Code Challenge does not test against variables or properties declared within the project. Hence, your answer [myArray objectAtIndex:0]; is perfect, just don't assign it to a label.

I think I should add that I feel the directions are not very clear for this section, as far as naming the label goes. It doesn't even say what I should call it.

Leif Sandaas
Leif Sandaas
14,275 Points

Thanks for the help Amit. I have a small question. In the code you taught us in the video the objectAtIndex number was in parens. Here is isn't. Does it make a difference?

Thanks

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

@leif Not sure where you saw that can you please provide a link or paste in the code?