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

Code Challenge : what is NSDictionary

What's wrong with my last line ? 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 : books1, books2,nil];

6 Answers

Stone Preston
Stone Preston
42,016 Points

check the names of your dictionaries. you declared them as book1 and book2. Now look at what you have as your objects in your array. They dont match up

The first two declarations passed, i made your changes but the last line still doesn't pass... :-/ 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, book2];

Stone Preston
Stone Preston
42,016 Points

you forgot your nil at then end of your arrayWithObjects. Try that and see if it works

Yes ! Thanks it worked !

I know your questions has already been answered Natacha but just a quick one which will help get your answers answered quicker, remember to add backtags before and after your code so instead of code looking like this..

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 : books1, books2,nil];

Which is near enough non-readable you can make it looks like this...

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 : books1, books2,nil];

These are the backtags you need - ```

bit quicker and easier for people to read and will get you a quicker reply :) (if you get stuck there is a link just above the post answer button to the markdown cheat sheet, hope this helps you in the future.

Yes Thanks ! I am a newbie so that's all useful info even if my question was already answered !

Jack,

I believe your code sample is wrong.

it should be:

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

not:

NSArray *booksArray = [NSArray arrayWithObjects : books1, books2,nil];

(you use 'book1 and book2 in the first two lines, not books1 and books2)

Also, it wouldn't pass with ",nil];"

I had to add a space between the comma and nil. Don't know why?