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?

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,773 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