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?

KAJAL SRIVASTAVA
KAJAL SRIVASTAVA
4,549 Points

Dictonary assignment

In part of dictonary task "Assign the value for key "UK" to a constant named ukCurrency."

either I am not getting the what you mean with question or missing very basic thing.

Can you please provide the solution.

2 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Kajal,

There's plenty of solutions on the forum for this specific question which is a bit vague if you're new to Swift and programming in general, so let's break it down.

  1. Define a constant called ukCurrency
  2. From the currencies dictionary select the <key:value> pair for UK
Still confusing?

Let's remember back to dictionary basics, for each <key:value> pair we have we can access the value using the key we've specified, for example.

let myDict = ["key1": "value1", "key2": "value2"]
println(myDict["key2"]) // results in "value2" being printed to the console

So let's apply that to the challenge, if we've done everything correctly we should end up with the following.

let ukCurrency = currencies["UK"]
// ukCurrency = Pound

Hope that helps.

Thanks Chris, I was stuck on this too!

KAJAL SRIVASTAVA
KAJAL SRIVASTAVA
4,549 Points

thanks Chris. It worked. I was assigning in last part in vice versa.