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 Build a Blog Reader iPhone App Getting Data from the Web What is NSDictionary?

Getting Data from the Web

Challenge task 3 of 3

Create an array called booksArray with the objects book1 and book2

NSDictionary *book1 = [NSDictionary dictionaryWithObjectsAndKeys:@"Art of War",@"Title",@"Sun Tzu",@"Author", nil]; NSDictionary *book2 = [NSDictionary dictionaryWithObjectsAndKeys:@"Brave New World",@"Title",@"Aldous Huxley",@"Author", nil];

My code for #3:

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

Result:

Bummer! Make sure you created an array with the correct variable name, and check your syntax!

2 Answers

 Vladimir Cezar
 Vladimir Cezar
7,710 Points

Details matter a lot. The challenge is 'Create an array called booksArray with the objects book1 and book2'. So the array should be named booksArray and not self.books.

Here is the complete code:

    NSDictionary *book1 = [NSDictionary dictionaryWithObjectsAndKeys:@"Art of War", @"Title", @"Sun Tzu", @"Author", nil];
    NSDictionary *book2 = [NSDictionary dictionaryWithObjectsAndKeys:@"Brave New World'", @"Title", @"Aldous Huxley", @"Author", nil];
    NSArray *booksArray = [NSArray arrayWithObjects: book1, book1, nil];

or, in a compact form:

NSDictionary *book1 = @{
                            @"Title":@"Art of War",
                            @"Author":@"Sun Tzu"
                            };
NSDictionary *book2 = @{
                            @"Title":@"Brave New World'",
                            @"Author":@"Aldous Huxley"
                            };
NSArray *booksArray = @[book1, book2];
 Vladimir Cezar
 Vladimir Cezar
7,710 Points

If this helps you, please consider selecting the answer as 'Best answer'. This helps my scoring and encourages me to keep answering your questions as well as other people. Thanks.

Thanks bud!