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 Objective-C Basics (Retired) Foundation Framework NSDictionary

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

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?

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

If you need more code I can give it to you.

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"];

Okay, I got it.

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

Got it! Thank you!