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

need help on code challenge Introducing the Project

The instruction says: Now switch to the implementation file and set the 'items' property to an array of two or more NSString objects using the 'arrayWithObjects' method of the NSMutableArray class.

What I have so far

NSMutableArray *array = [NSMutableArray arrayWithObjects:@"items"];

I'm not quite sure the next step. Can someone help me out? Thanks

2 Answers

Patrik Alam,

Unfortunately the example code isn't quite what the task is looking for, so let's correct this. In the example, a new NSMutableArray object called 'array' is being declared and initialized. This new 'array' object is not necessary because our InboxViewController class already has a property called 'items' that we declared in the previous task. This task wants us to use that property instead. So we can remove the left side of the '=' sign in the example code and replace it with 'self.items'. If we do that the code will change to the following:

self.items = [NSMutableArray arrayWithObjects:@"items"];

Ok, so now on the right side of the '=' sign the example code was headed in the right direction. But the task wants us to set two or more NSString objects to the 'items' property. The example code was one string object short. With the 'arrayWithObjects' class method we can initialize the NSMutableArray object with more than one object at a time. We just have to separate each object with commas (,) and end our list of objects with the keyword 'nil'. So lets add 'another item' to the list of objects. In the end our code will look like:

self.items = [NSMutableArray arrayWithObjects:@"items", @"another item", nil];

This new line of code should work. I hope this clears up any confusion you might have had.

Thanks again David!

You're welcome

Thanks Ben :)

Thanks David!

A truly great answer. Keep up the good work David :)