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

Stuck on "Create an array called booksArray with the objects book1 and book2"

I'd prefer that you don't give me the answer, but perhaps some guidance. Am I even close?

This is what I tried.

self.booksArray = [NSArray arrayWithObjects: book1, book2, nil];

Mineral Studio
Mineral Studio
13,945 Points

yes. Me too. Stuck on this session

4 Answers

R Brewster
R Brewster
15,328 Points

This also works. NSArray *booksArray = [NSArray arrayWithObjects: book1, book2, nil];

NSArray *booksArray = [NSArray arrayWithObjects: @"book1", @"book2", nil];

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!

Mineral Studio
Mineral Studio
13,945 Points

yes. Me too. Stuck on this session