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?

Mehran Amini Tehrani
Mehran Amini Tehrani
1,523 Points

Dictionary

Hello,

How can I Assign the value for key "UK" to a constant named ukCurrency?

dictionaries.swift
let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"]
let ukCurrencey = ["UK": "Pound"]

6 Answers

Mehran Amini Tehrani
Mehran Amini Tehrani
1,523 Points

It should be like this:

let ukCurrency = currencies["UK"]

Mehran you are right. I wanted to write the same but I forgot to change it when I copied your code and didn't see that until you said. I am happy you found a solution.

Happy coding and keep learning

Well, you already did that :) You assigned key "UK" for value "Pound" to constant name ukCurrencey

Mehran Amini Tehrani
Mehran Amini Tehrani
1,523 Points

Yes, but it gives me an error "You need to define 'let ukCurrency' ". How can i define it?

It gives you an error because you made spelling mistake. You wrote ukCurrencey, what you need to write is ukCurrency

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

Ive tried doing it that way and i get " Your code could not be compiled. Please click on "Preview" to view the compiler errors." when i check the preview there's nothing, Im i doing something wrong?

Try to copy my code. Does it pass?

I was misunderstanding the question in general, the answer was: let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"] let ukCurrency = currencies["UK"]