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 trialDavid Petrin
3,384 PointsWhat is wrong with my second line of code?
What is wrong with my second line of code?
let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"]
let ukCurrency = currencies.removeValueForKey("UK")
2 Answers
Greg Kaleka
39,021 PointsHi David,
Because you used let
to declare your dictionary, it's a constant, and you can't use removeValueForKey
on it. Change let currencies
to var currencies
and it would work. However, there's no reason to use removeValueForKey
in this case - you don't need to change the dictionary. Instead, just index into it and grab the value for "UK".
let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"]
let ukCurrency = currencies["UK"]
Best,
Greg
David Petrin
3,384 PointsThanks for the help Greg!