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 trialBeau Waldrop
1,341 PointsStuck 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];
4 Answers
R Brewster
15,328 PointsThis also works. NSArray *booksArray = [NSArray arrayWithObjects: book1, book2, nil];
Gregg Mojica
11,506 PointsNSArray *booksArray = [NSArray arrayWithObjects: @"book1", @"book2", nil];
Ernest Grzybowski
Treehouse Project ReviewerIt 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
13,945 Pointsyes. Me too. Stuck on this session
Mineral Studio
13,945 PointsMineral Studio
13,945 Pointsyes. Me too. Stuck on this session