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?

Oleg Shamin
Oleg Shamin
1,798 Points

Hello. How I can finish this challenge, if it has an error every time? I think,I must print "var currencies", not "let"

When I trying finished 2 object, I have an error every time. I think its because I use "var currencies", but not "let currencies"

dictionaries.swift

1 Answer

Stone Preston
Stone Preston
42,016 Points

it needs to be let

task 2 states: Assign the value for key "UK" to a constant named ukCurrency.

you dont change the value assigned to the key "UK", you assign the value of that key to a new constant:

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

let ukCurrency = currencies["UK"] // ukCurrency now has a value of "Pound"
// currencies remains unchanged, with a value of [ "US": "Dollar", "UK": "Pound", "JP": "Yen"]

this does not modify the currencies dict at all, you just access a value from it. nothing in the dictionary changes. you are basically saying "give me the value that corresponds to this key, and assign that value to this constant". it doesnt change anything about the dictionary itself