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 Swift Basics (retired) Collections What is a Dictionary?

Assign the value for key in dictionary

if i define currencies as constant i can't change it, but with var currencies it's working in the playground

dictionaries.swift
var currencies = ["US" : "Dollar", "UK" : "Pound", "JP" : "Yen" ]
let ukCurrency = currencies.removeValueForKey("UK")

Your code is compiling fine for me.

When you declare currencies as a constant you are explicitly telling the program that you don't want its values to be modified. That's why you can't call removeValueForKey() unless currencies is declared as a variable.

I misunderstood your problem before.

1 Answer

Dennis Parussini
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Dennis Parussini
Treehouse Project Reviewer

Took me a while but now I see what's wrong. ;-)

In this challenge you don't need to use .removeValueForKey(). You only have to assign the value of the currency to a new constant.

So, your code should look like this:

let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"]
let ukCurrency = currencies["UK"]

If you need further help I'd be glad to help.