Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Basics (retired) Collections What is a Dictionary?

note: change 'let' to 'var' to make it mutable

Should this really work?

I'm trying it in a playground too and it is complaining that I have the constant currencies while trying to assign constant ukcurrency a value.

The error in playground is:

"note: change 'let' to 'var' to make it mutable"

On tem treehouse, is complains that code cannot be compiled but doesn't make sense to me when I check the errors.

dictionaries.swift
let currencies = ["US": "Dollar", 
                "UK": "Pound",
                "JP": "Yen"]

let ukCurrency = currencies.removeValueForKey("UK")

Hi Shane,

I do not believe this should work as currencies is set to be a constant and therefore once set cannot be altered (constants are immutable), should you need to change it then changing it from a constant to a variable should work:

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

let ukCurrency = currencies.removeValueForKey("UK")

Hope that makes sense. Happy coding :octopus:

1 Answer

I agree with you Kieran but that doesn't seem to be the case here. Your code also gets rejected because it wants to have dict as constant.

The question is :

"Create a constant named ukCurrency. Assign the value from the currencies dictionary. Use the key of "UK" to access the value."

But the previous questions was: "Let's create a dictionary that contains the currencies of the various countries along with their country codes. The country code will be the key and the currency the value. Using the following key-value pairs: US : Dollar, UK : Pound, JP : Yen assign them to a constant named currencies."

I don't believe I can work past this?