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 trialRasmus Pedersen
4,093 PointsProblems with removeValueForKey when the dictionary is a constant
The task asked me first to create a constant called currencies with the dictionary consisting of a variety of currencies, no problem.
let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"]
After that the task was to assign the UK currencies to a constant called "ukCurrency"
let ukCurrency = currencies.removeValueForKey("UK")
I ran the code through x-code, and it all worked if I changed the constant "currencies" into a variable. But the task wont accept that approach. I have probably misunderstood something, please help :)
3 Answers
Vittorio Somaschini
33,371 PointsHello Rasmus.
I do not think that you should call that removeValueForKey method here.
The task simply asks you to create a constant with that value, but you don't need to actually touch the dictionary.
You only need to create the variable, using the right value (assigned to the right key) in the dictionary.
So something like this:
let ukCurrency = currencies["UK"]
Where currencies["UK"] ask the compiler to look for the value with the key "UK" in that dictionary.
I hope it is clear.
Vittorio
Arman Kussainov
4,754 PointsYou should change the type to "var".
Rasmus Pedersen
4,093 PointsHello Arman
If I change the dictionary into - var currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"]
I get "Bummer! You need to define a constant named 'currencies'."
Rasmus Pedersen
4,093 PointsRasmus Pedersen
4,093 PointsHello Vittorio
That was correct, thanks a lot :)
Looks like I made the task more complex than it was