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?

Dictionaries

Assign the value for key "UK" to a constant named ukCurrency.

The below is the first statement,

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

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

you have to do in this way : let ukCurrency = countries("UK") and in the array give a gap between ["US": "Dollars", "UK": "Pound"].

1 Answer

Peter Kullmann
Peter Kullmann
14,267 Points

After assigning key-value pairs to a dictionary you are ready to work with them, for example by updating or removing values or by iterating over the key-value pairs with a for-in loop as you will learn at a later stage of the Swift Basics Course.

Let's take look at an example similar to Apple's Swift documentation about Collection Types:

var airports = ["YYZ": "Toronto Pearson", "DUB": "Dublin"]
let airportName = airports["DUB"]

At this point, the value of the constant airportName is the string "Dublin" - the value of the second key-value pair

In this particular Code Challenge, you want to access the value of "UK" which is the key linked to its value "Pound". Therefore, you have to adjust the code above to fit the task.

I hope that gives you a better understanding of the Code Challenge. In case you are still having difficulties solving it, feel free to ask me or see Apple's documentation which often can be very helpful for making sense of specific Swift programming problems.