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!
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
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];
R Brewster15,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!