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 "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