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?

Stuck!

it asks to assign the value for the key `uk to a constant named ukCurrency so the value for the key uk is pound and I've named the constant ukCurrency so why is it wrong? Thanks

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

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello Alia:

The challenge says : Assign the value for key "UK" to a constant named ukCurrency.

So you have to give the value for the key “UK” to a constant name ukCurrency. Meaning that you don’t have to directly give it “Pound”, you have to use the Key.

let ukCurrency = currencies["UK"]

What you were doing in your answer was creating an Array name ukCurrency with a single item in it.

Hope you get it now, if you need more help please let me know or tag me in your questions with @jhoanarango

omg i swear I tried that and it wouldn't accept it ! haha I'll do it again thank you so much Jhoan I will do

oops just checked i didnt add the currencies bit why is that neccersary?
Jhoan Arango

Jhoan Arango
Jhoan Arango
14,575 Points

Alia:

It’s the only way the system knows what you are talking about, otherwise it would be lost.

Say that you have different dictionaries, how would the system know which key from which dictionary you are talking about?

For Example

// We have 2 dictionaries 

var carDictionary = ["FD":"Ford","FE":"Ferrari","LA":"Lamborghini"]
var cityDictionary = ["MIA":"Miami","LA":"Los Angeles","FLL":"Fort Lauderdale"]

/*
        How would you point out to the system you want the item “Miami” ?
*/

// We tell the system by giving it the name of the dictionary, and the key value for that item.

var cityOfMiami = cityDictionary["MIA"]

That’s why it is necessary :)

Hope this explanation helps you understand a bit better. It will make more sense as you practice

Happy coding, and remember to use @jhoanarango if you need more details :)