Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

Learning the Language > Code Challenge: Getting to Know Arrays

Still cant get passed 2/2, how do i acces the first fruit in array from this. Should this "self.predictionLabel.text " be something else, there are no instructions that I can find in vid. And why is the video training making a crystal ball and the challenge about fruit, it seems odd. I have taught in the past, and there seems to be continuity errors here between vid and challenge...remember Treehouse, we are probably newbies, spoon feed us please.....or at least I can only speak for myself.......Ive been trying to solve this for well over a week now.

NSArray *myArray = [[NSArray alloc] initWithObjects: @"Apple",@"Orange",@"Banana",@"Plum",nil];

self.predictionLabel.text = [myArray objectAtIndex:0];

3 Answers

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

Sorry you are having trouble. The goal of Code Challenges are not to make you simply type what you saw in the video. The goal is to see if you can apply what you learned in the video in a different context. Hence the reason for fruits in the Code Challenge. Your answer is right except that you are not setting the value you access from the array to any label. The Code Challenge is simply to test to see whether you can create an array and know how to access an object. There is no UI so there is no label.

So your second line will simply be:

[myArray objectAtIndex:0];
J.T. Gralka
J.T. Gralka
20,126 Points

Karl,

I don't think you have to do anything with a UILabel, so you should just be able to access the array at a particular index by doing something like this:

    [myArray objectAtIndex:0]; // Get the first element of the array...

Hope this helps,

J.T.

Edit:

It looks like Amit answered this question before I did; sorry for reiterating what was already said! Hopefully you're on the right track now!

Ahh thanks, I can see now.. Feeling a little humbled and less stressed, thanks guys :)