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

David Ashworth
David Ashworth
718 Points

Bug in NSDictionary challenge step 2

My code below which the challenge says is incorrect:

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

NSMutableDictionary *albumMutable = [[NSMutableDictionary alloc] initWithDictionary:album];

The error says I should be using the 'dictionaryWithDictionary' class method to initialize the new NSMutableDictionary... don't think that's right... can't continue now. :(

2 Answers

Stone Preston
Stone Preston
42,016 Points

since the challenge error says you need to use the dictionaryWithDictionary class method to pass you should probably try

NSMutableDictionary *albumMutable = [NSMutableDictionary dictionaryWithDictionary:album];

while what you had first is correct as well, in this case the challenge wants you to use the dictionaryWithDictionary convenience constructor.

David Ashworth
David Ashworth
718 Points

Righto--that works, thanks. I could have sworn they had used what I wrote in the code in the tutorial video, but going back now I see I'm mistaken. They did actually use dictionaryWithDictionary. Time for sleeping.