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?

Maka Haidara
Maka Haidara
442 Points

I m having serious difficulties with that exercice. What is the correct answer ?

The challenge task 2of 2, i really don't get it. That s my answer i don' t where is my mistake let currencies = [ "US": "Dollar", "UK": "Pound", "JP": "Yen" ] let ukCurrency = [ "UK": "Pound" ]

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

2 Answers

Jhoan Arango
Jhoan Arango
14,575 Points

Hello Maka:

Very good.. You almost got it, but here is how you want to do this

let ukCurrency = currencies["UK"]

The seconds part of the challenge is worded in a somewhat difficult to discern way, but if you read carefully the challenge can be translated as "Create a new constant and name it ukCurrency, then give it the value "Pound".

let ukCurrency = "Pound"
Jhoan Arango
Jhoan Arango
14,575 Points

Hi Kyle:

Not that I want to contradict your answer. The challenge says Assign the value for key "UK" to a constant named ukCurrency.

This will be assigning

let ukCurrency = currencies["UK"] 

// If you call ukCurrency you’ll see its value which is β€œPound"

What you are doing is declaring a constant name ukCurrency, and giving it the value of β€œPound”. The compiler takes this as the right answer and allows the challenge to be passed, but it’s not the answer they are looking for. Because this is declaring a constant, something that was shown in the first parts of swift basics. This challenge is about capturing a value from a dictionary.