Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.