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?

William Crawford
William Crawford
4,319 Points

Swift CollectionsnStg 4,Chg 2of2-Dictionary

I got part one. My question is, how can you change the value of a constant? let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"] currencies["UK"] = "uKCurrency" gives a mutability error, and so does: let uKCurrency = currencies.updateValue("uKCurrency", forKey: "UK") The challenge says to define "uKCurrency", which I thought I did? I may move on, and come back. Help appreciated.

4 Answers

Logan R
Logan R
22,989 Points

Good tries, but all you need to do to assign a variable a key is to do:

Array["key"]

So in this case:

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

let ukCurrency = currencies["UK"]
William Crawford
William Crawford
4,319 Points

Thanks, Logan. I think I had tried that before. I tried it now, and get the reply: Bummer! You need have let ukCurrency defined.

Logan R
Logan R
22,989 Points

What is your code? The second block of code I have works, as I have tested it.

William Crawford
William Crawford
4,319 Points

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

Logan R
Logan R
22,989 Points

It's ukCurrency, not uKCurrency. The program is case sensitive :)

Also, I accidently pressed best answer, lol, sorry. I unchecked it.

William Crawford
William Crawford
4,319 Points

Ooooooh. Thanks, Logan. I swear I saw uKCurrency. I was typing it on purpose - wrong. Thanks for the help!!

Logan R
Logan R
22,989 Points

No problem :) If you have any more questions, feel free to post them on the forums!