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?

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?