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


cameryn smith
cameryn smith
2,828 Points

I need Help creating an NSDictionary object?

On the code challenge 'Getting Data from the Web' I need help declaring an NSDictionary in task 1. I'm still confused, is it key-value or value key.

This is how I initialized it: NSDictionary *example = [NSDictionary dictionaryWithObjectsAndKeys: @"etc..", nil];

2 Answers

This may be very confusing in Objective-C, but be aware that the value comes before the key in Objective-C.

In your example, you haven't defined what's the key of the dictionary you're making after your value of @"etc", nor is it clear what@"etc"` is even a value missing a key.

The simplest way to create a NSDictionary in Objective-C is through a dictionary literal @{@"key":value};. That said, the challenge likely won't accept that way of defining a NSDictionary for you to learn how to do it the old-fashioned way for now.

cameryn smith
cameryn smith
2,828 Points

Hey dude thx this is what I typd, thx for clarifying.

NSDictionary *book1 = [NSDictionary dictionaryWithObjectsAndKeys: @"Art of War",@"Title",@"Sun Tzu",@"Author", nil];