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?

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!