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.


Trae Cadenhead
Trae Cadenhead
6,774 Points

Stuck on a Code Challenge in Build a Simple iPhone App with Objective C

Hello, I'm trying to get past a code challenge in "Build a Simple iPhone App with Objective C." I'm pretty positive my code response is correct (the preview isn't showing any errors), but it won't let me pass saying I have to add all three items to the array (which I am). I'm also including a screenshot.

The URL for the challenge is https://teamtreehouse.com/library/build-a-simple-iphone-app-with-objectivec/creating-a-data-model/creating-a-data-collection-2

My line of code for initializing the array:

[self.shoppingList initWithObjects: @"toothpaste", @"bread", @"eggs", nil];

Screenshot here: https://www.dropbox.com/s/4ikazdw40lkry4l/treehouse%20screenshot.png?dl=0

1 Answer

You need to initialize the array before you can use it

self.shoppingList = [[NSArray alloc]initWithObjects: @"toothpaste", @"bread", @"eggs",nil];

what you have in the screen shot is basically:

["toothpaste", "bread", "eggs"]
Trae Cadenhead
Trae Cadenhead
6,774 Points

Ah, that makes sense. Thanks Marlon!

No problem anytime I can help is a good day for me. When you can explain it to someone that means you really understand what you are doing(and means I'm getting paid to do this in my day job for a real reason lol.) don't forget to mark me as the best answer, trying to get these treehouse points anyway I can lol.