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?

Marie Jose Lemiere
Marie Jose Lemiere
872 Points

Hello, I do not understand the challenge "Assign the value for key "UK" to a constant named ukCurrency." Thank you

Are we modifying the key value pair for UK ? I do not understand. Thank you

dictionaries.swift
let currencies = [ "US": "Dollar", "UK": "Pound", "JP": "Yen" ]
Roberto Alicata
Roberto Alicata
Courses Plus Student 39,959 Points

You have to define a new constant named ukCurrency then you must assign the value for the key "UK" to the constant you just created

let ukCurrency = ...........
Marie Jose Lemiere
Marie Jose Lemiere
872 Points

Thank You I did : let ukCurrency = ["UK"] I also did : let ukCurrency = ["UK":"Pound"] but it still doesn't work. What did I miss ?

Roberto Alicata
Roberto Alicata
Courses Plus Student 39,959 Points

You need to read the value from the dictionary. To do it you must write the key you know ("UK" in this case):

currencies["UK"]

then if you want to store the value in a constant (or a variable) ....

let ukCurrency = currencies["UK"]

2 Answers

let ukCurrencies = currencies[key] // you should figure it out
// to reference values from a dictionary you use the key i.e x['b'] = 'hello world' 

remember to mark best answer :)