Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Objective-C Basics (Retired) Foundation Framework NSDictionary

NSDictionary Challenge task1

The challenge states: Declare an NSDictionary variable named 'album'. Assign the following key/pairs to it: "title" - "Abbey Road", "artist" - "The Beatles".

I entered the following solutions:

  1. NSDictionary *album = @{@"title":@"Abbey Road",@"artist":@"The Beatles"};
  2. NSDictionary *album = [[NSDictionary alloc] initWithObjectsAndKeys:@"title",@"Abbey Road",@"artist",@"The Beatles", nil];

however, for both the above attempts the system returned the message: Bummer! your album dictionary has no values.

What am I doing wrong?

1 Answer

Stone Preston
Stone Preston
42,016 Points

I tried your first line of code and passed fine using

NSDictionary *album = @{@"title":@"Abbey Road",@"artist":@"The Beatles"};

so im not sure what was wrong but it should have worked

however there is an error in the second way you tried. If you use that method the values come before they keys like so:

NSDictionary *album = [[NSDictionary alloc] initWithObjectsAndKeys:@"Abbey Road",@"title",@"The Beatles", @"artist", nil];