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?

Jeremy Turner
Jeremy Turner
1,567 Points

Assign the value for key "UK" to a constant named ukCurrency. Could someone provide the answer and explain it? Thanks!

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

8 Answers

It is pretty easy to get the object associated with the key. Do:

Array["key"]

So in this case:

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

let ukCurrency = currencies["UK"]
Jeremy Turner
Jeremy Turner
1,567 Points

Thanks Logan. It was super easy. I was embarrassed to even ask. lol

Don't be embarrassed :) Everyone, even myself, have to ask questions to learn. If you ever have any more questions, feel free to post them on the forums!

i had the same question from the challenge question. I got confused on the optional intro from the dic lecture. thnx a lot guys.

Jeremy Turner
Jeremy Turner
1,567 Points

Glad to know I'm not alone Lol

I'm stuck on this quiz question. My code was exactly as you have above, but I keep getting an error "Your code could not be compiled. Please click on "Preview" to view the compiler errors.". the errors don't load?

so I had to reload the lesson a few times before it let me pass. weird.

I find myself thinking way too hard re: questions!

I thought we needed to remove the key first and then assign it a value. So just to be clear on the conceptualization, the reason why we don't do this is simply because the key/items in the array are not variables?

In this case, it is not removed because you may want to use the same value again later in the program.

ough, thank you for the help. Easier than i thought.

Had the same question. Thanks!

Me too! I was stuck for a minute lol. Thanks!