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

stuck on arrays - "create an array with the following fruits....

Hi, I am still stuck on this problem, had another post open. Can you point me in the right direction? I am a complete newbie to this...

Ive watched the video over and over.... I could act in it .....

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

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

3 Answers

I think your problem has to do with this line:

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

I'm not sure why you're including this line or what you're trying to do with it. Try getting rid of it, because I think the code challenge question just asks you to define and instantiate the array (which you seem to have done successfully).

Good luck,

J.T.

It helps to give us where you encountered the problem. Can you please post which lesson this is from exactly? It's important to know which lesson, because different lessons provide different ways to do the same thing.

One way to create an array with Fruit:

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

Second way to create an array with Fruit:

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

I believe the first example is taught early on, and the second example shows you how to combine the two lines into one. Hope this helps. Keep on coding!

I was stuck on 1 of 2 , getting know arrays, I initially carried over this (self.myArray.text = [myArray objectAtIndex:0];0 as I thought this was a continuation of the code from the previos lesson!

Im now stuck on challenge 2 of 2 , acces the first fruit in array, I will watch video again, this time maybe i will geti it!