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?

javier graterol
javier graterol
6,056 Points

you cannot modify a constant, and that is what they ask you to

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

They ask you to define a constant and in the video they use a variable. Then they tell you to modify that constant but since is a constant this can't happen.

What to do?

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

1 Answer

Max Hirsh
Max Hirsh
16,761 Points

Hey, so I checked out the challenge you're talking about and the task is "Assign the value for key 'UK' to a constant named ukCurrency." To access the value of a dictionary, there is no need to modify the dictionary in any way. You just need to type dictionary["key"]. In this example your last line of code would look like:

let ukCurrency = currencies["UK"]

Hope this helps!

javier graterol
javier graterol
6,056 Points

You were right, thank you for the time. My bad