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

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

I can't figure out whats wrong with my code.

Whats wrong with my code? I can't figuer it out.

[albumMutable setObject:@1969 setKey:@"year"];
NSLog(@"%@", albumMutable);

Here is the warning:

instance method '-setObject:setKey:' not found (return type defaults to 'id')
 [albumMutable setObject:@1969 setKey:@"year"];
               ^~~~~~~~~~~~~~~~~~~~~~
note: receiver is instance of class declared here
@interface NSMutableDictionary : NSDictionary
           ^
1 error generated.

8 Answers

Andres Oliva
Andres Oliva
7,810 Points

Ok, I know what's going on.

The challenge task reads: Let's add the year of the album to the 'albumMutable' variable. Where the key is a NSString 'year' and the value is also a NSString '1969'.

That means your code should be:

[albumMutable setObject: @"1969" forKey: @"year"];

Not

[albumMutable setObject: @1969 forKey: @"year"];

I just tried it and it works.

What are you workng on?

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

The NSDictionary challenge, Foundation Framework badge, in the Objective-C Basics course; I'm on step 3.

Andres Oliva
Andres Oliva
7,810 Points

That means that the method you're calling doesn't exist.

If I understand correctly, what you need is this:

[albumMutable setObject: @1969 forKey: @"year"];

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

It said my answer was wrong: Bummer! The year set is not the correct value.